Add 0x before sending RS232 messages

Hi, I have an issue using comwrt function, the message I d like to send is like 0103040F000F unfortunately comwrt function convert each character as  hexadecimal ascii so the message sent looks like 30 31 33 ...... and I actually like to send the exact message 0103040F000F  on port so I have tried to use comwrtbyte function sending my datas byte per byte 01, 03 but I cannot send A to F values literally I must put a 0x before each, but I don't know how to put the whole thing in a variable,
int SendMessage (char *in)
    int len = 0;
    int i=0;
    int val=0;
    int ByteToSend;
    char *CharByteToSend;
    char Hexa[3]; Hexa[2]=0;
    len = strlen(in);
    CharByteToSend=(char*)malloc(5*sizeof(char));
    CharByteToSend[0]='0';
    CharByteToSend[1]='x';
    do                                 
        strncpy(CharByteToSend+2, in+i, 2);  CharByteToSend[4] = 0;
        ByteToSend = atoi(CharByteToSend);
        ComWrtByte(1, ByteToSend);
        i++;
        *in++;
    while(i<len);
    return 0;

Hi Olivier,
I am attaching the code fragments I use for CRC calculation and control in Modbus protocol: take a look and see if they give you the correct results. These have been used with several instruments (Siemens S7 plc, CHINO and CAL Controls temperature regulators and so on) so they should be ok for you too.
Before any instruction:
#define CRC16  0xA001     // To calculate CRC tables
static unsigned char crc_table_1[256];  // Table for CRC1 calculation
static unsigned char crc_table_2[256];  // Table for CRC2 calculation
At program start (or before you begin preparing Modbus messages with their CRC):
//                             Initialize tables for CRC calculation
void InitCRC(void)
 unsigned char i;
 unsigned int mask, crc, mem;
 for (mask = 0; mask < 256; mask++) {
  crc = mask;
  for (i = 0; i < 8; i++) {
   mem = (unsigned int)(crc & 0x0001) ;
   crc /= 2;
   if (mem)
    crc ^= CRC16 ;
  crc_table_2[mask] = (unsigned char) (crc & 0xff); // lobyte
  crc_table_1[mask] = (unsigned char) (crc >> 8);   // hibyte
 return;
Calculate CRC when preparing a message to send out:
//          Computes the CRC and append to the buffer with the data to be transmitted
// Parameters:    buf = message buffer
//                size = lengh of message buffer excluding the crc (crc will be appended to buf
//                         so you must pass a buffer with extra lenght)
// Return values: none
void CalcCRC(unsigned char * buf, unsigned char size)
 unsigned char car, i;
 unsigned char crc0, crc1;
 crc0 = 0xff;
 crc1 = 0xff;
 for (i = 0; i < size; i++) {
  car  = buf[i];
  car  = * ((unsigned char *) buf + i);
  car ^= crc0;
  crc0 = (unsigned char) (crc1 ^ crc_table_2[car]);
  crc1 = crc_table_1[car];
 * (buf + size)     = crc0;  // CRC low
 * (buf + size + 1) = crc1;  // CRC high
 return;
When checking CRC on a received message:
//           CRC check and match with the CRC found on the received data buffer
// Parameters:    buf = message buffer
//                size = lengh of message buffer excluding the crc
// Return values: 0 if CRC ok
//                1 if CRC bad
//                If CRC is bad the data packet is corrupted, so it is necessary to discard it.
int CheckCRC(unsigned char * buf, unsigned char size)
  unsigned char car, i;
  unsigned char crc0, crc1;
  unsigned int  crc_calc, crc_read;
  crc0 = 0xff;
  crc1 = 0xff;
  for(i = 0; i < size; i++) {
    car  = buf[i];
    car  = * ((unsigned char *) buf + i);
    car ^= crc0;
    crc0 = (unsigned char) (crc1 ^ crc_table_2[car]);
    crc1 = crc_table_1[car];
  crc_calc  = (crc1 << 8) + crc0;
  crc_read = * (buf + size) + 256 * (* (buf + size + 1));
  return (crc_read != crc_calc);
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos?

Similar Messages

  • Send data via HTTP and wait 10 Seconds before sending next Message

    Hi Folks,
    I am doing an IDOC - XI - HTTP scenario.
    after sending a message via the HTTP-receiver I have to wait up to 10 Seconds, before my partner accept the next Message.
    Is there a way to configure the HTTP-receiver to wait?
    Thanks,
    Chris

    Hi Chris,
    You can use ccBPM for this scenario.
    Scenario 1 :
    1 IDOC contains multiple records, so you can convert to multiline items.
    Loop base on the multiline items (Block Step).
        Send Step for sending http request.
        wait step to wait for 10 seconds.
    Scenario 2 :
    1 IDOC contains only single record. so you need to collect the IDOC until certain time.
    Loop base on the multiline items (Block Step).
        Send Step for sending http request.
        wait step to wait for 10 seconds.
    Regards
    Fernand

  • How can I get TB in my Mac to ask me before sending the messages in Outbox?

    Something has changed and TB is now sending the messages I created to Send Later (which are in the Outbox) without asking me as soon as I re-connect to a network (i.e., it correctly stores it into the Outbox but if my laptop loses the network-- because for example I close it to go home -- as soon as it reconnects it sends all messages without asking me).
    I have a Mac and I cannot find the Advanced > Network & Disc Space settings that (https://support.mozilla.org/en-US/questions/1004514) indicates as the solution.
    Any help would be greatly appreciated.
    Thanks!

    ''mgba [[#question-1052447|said]]''
    <blockquote>
    Something has changed and TB is now sending the messages I created to Send Later (which are in the Outbox) without asking me as soon as I re-connect to a network (i.e., it correctly stores it into the Outbox but if my laptop loses the network-- because for example I close it to go home -- as soon as it reconnects it sends all messages without asking me).
    I have a Mac and I cannot find the Advanced > Network & Disc Space settings that (https://support.mozilla.org/en-US/questions/1004514) indicates as the solution.
    Any help would be greatly appreciated.
    Thanks!
    </blockquote>
    Thanks Matt, perfect!
    Cheers,Maria

  • Can't send an email but get a message in a yellow box that says,"To stop spammers, we sometimes ask you to enter characters before sending your message

    OK, for the umpteenth time, Unable to send out emails!!!!!

    Duplicate. Continue in original post: https://support.mozilla.com/en-US/questions/860870?s=&as=s

  • Won't send email but says to enter characters to stop spammers before sending message.

    I tried to send an email and this message pops up in a yellow box that says "To stop spammers, we sometimes ask you to enter characters before sending your message."

    '''We are ''unpaid'' volunteers, here to help other users.'''
    *Ask a question and be patient while waiting for an answer; you posted this question 3 times within 12 minutes.
    *Be courteous when asking for assistance from a volunteer.

  • How to send a message to a Facebook friend from shortcut of messages in notification center

    i tried to send a message to a facebook friend from the shortcut of messages like facebook post or twitter tweat option in notification center but i couldn't i thought there may be something else which i need to do before sending a message to anyone from facebook is there something i need to get done before i can a message to a facebook friend ???

    Hi,
    I take it you have a Jabber account set up in Messages ?
    A Google Mail ID can access Google talk which is a Jabber Server and if you have Enabled "Chat" at Facebook you will have a Facebook chat ID that can be used in Messages as they too run a Jabber server.
    Of course these are just two of many Jabber and compatible XMPP servers.
    I don't have Facebook or Twitter but I did use the Menu bar icon for Notifications  and clicked Messages and Sent a Messages to one of my Jabber IDs (it logged me in and sent it from my Google one).
    In the System Preferences > Notifications I do have Share Button set (Messages only).
    9:04 pm      Saturday; May 10, 2014
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

  • Any way to make Mail.app receive before send?

    I work at an ISP and we have a customer who is outside of our range, using Mail.app to connect to our POP3 server.
    Normally we have them use their provider's outgoing mail server, and our incoming mail server since our mail server rejects e-mails originating outside of our IP pool. Usually this works.
    However, the customer's provider blocks use of their outgoing mail server if the e-mail address is from a different domain.
    The one solution would be to have Mail.app receive (and thus authenticate with our mail server) before sending.
    Is there any way to do this?

    Are you talking about POP before SMTP authentication and if so, are you saying the account must check the incoming mail server for new mail immediately before sending mail with the account's SMTP server and this must occur each time before sending mail?
    I thought when POP before SMTP authentication is used/required, checking the incoming mail server for the account at least once per online session is all this is required, not each time immediately before sending mail.
    There is no setting to do so in Mail but you can manually select Get Mail before sending a message if I'm understanding this correctly.

  • Cannot open Word document attachment in mail before sending.

    Cannot open Word document attachment in mail before sending.
    In Snow Leopard Mail 4, (Version 4.0 (1075/1075.2)) if I attach a word document to a message and, BEFORE sending the message, I double click the attached document to open it, to make sure it is the right one, I get the error "Mail was unable to save the attachment “Test.doc” to disk. Verify that your downloads folder exists and is writable."
    The attachment is mailed correctly and arrives at the destination, but the ability to verify an attached document before sending it is essential. This has worked fine in all previous editions of OS X.
    Any ideas?
    Thanks - Lawrence

    I have same problem. I've done the following testing to pinpoint where the problem lies and there are clues (see below):
    1. My machine had SnowLeopard installed "fresh" (i.e. disk reformat and installed cleanly)
    2. I have a comparison machine running Leopard (10.5.6) - essentially a mirror but with different OS
    3. Problem is triggered when creating new email, with a MS Word .doc attachment added. If you attempt to open the attached file in the mail (not yet sent) it produces the error message "unable to save file XXX.doc to disk. Verify that your downloads folder exists and is writeable"
    4.However, once the mail is sent, the recipient can open the attachment without problems.
    5. I have run Disk Utility and all permissions are correct. My downloads folder exists.
    6. The problem is not present in Leopard (mirror machine other than OS)
    7. I have uninstalled and reinstalled MS Office. Problem still present
    8. I have deleted and recreated the preference files for both MS Office and for Mail. Problem still present.
    And finally...
    9.The problem is confined to .doc files.It works fine for .pdf, .ods AND even for Microsoft .xls files.
    So it may be a MS Word problem triggered by Snow Leopard?
    Apple: if you can confirm this is a Microsoft problem it may be able to be reported to them as a compatibility issue?
    Hope this helps.

  • Send Sip Message with UDP transpot

    How to make to send a message with transport UDP?
    Message was edited by:
    nicvas

    Though the doMessage is being invoked on the server, the exception would arise when the server fails to send the message to the callee.
    Check if there is any callee listening on: 192.168.1.104:1,107. Thats where the server is trying to send the message.
    Make sure 2 text clients are running and have registered with the chat server before sending the message from one to the other.
    hope this helps,
    mihir

  • Edit a mail message before sending

    How do I edit an email in Mail while spell-checking? Sounds simple, but my stupidity means I can't find out how to do it.
    Here's my scenario: I write a message, hit send and it brings up the spellchecker. Then while doing the spellcheck, I realise that I want to add or alter something in the email. So I come out of the spellchecker, either by closing it or just clicking on the body of the message, and try to edit the email. But when I then click in to the text I want to change and hit a key, any key it seems. the email just sends - doesn't give an opportunity to make those changes.
    This has to be something so obvious that I will cringe with embarrassment when I read the answer, but I hope someone will take pity on me and give me the answer!
    Thanks to that person!
    BTW, the thing is I only started using Mail a short while ago, having been a confirmed Thunderbird user...
    Ian

    Hi Lavakumar,
    Based on my knowledge, getting an alert before sending messages can't be achieved by Exchange Server.
    I would like to know what your purpose is. If you want to avoid users from sending wrong messages, recall feature can help them when they send wrong messages.
    For more information about recall, here is a helpful thread for your reference.
    Recall or replace an email message that you sent
    http://office.microsoft.com/en-us/outlook-help/recall-or-replace-an-email-message-after-it-is-sent-HA010354931.aspx
    Hope it helps.
    If you need further assistance, please feel free to let me know.
    Best regards,
    Amy
    Amy Wang
    TechNet Community Support

  • When I send an email with Mail, I often confuse the account which I'm using. The result is that I send a message with the wrong account! Is there a way to avoid this (for example a reminder before the email is sent)?

    When I send an email with Mail, I often confuse the account which I'm using. The result is that I send a message with the wrong account! Is there a way to avoid this (for example a reminder before the email is sent)?

    Hi, thanks for the answer, I did that already. Unfortunatly this doesn't help me at all, as I often forget to check the menu. For me composing the message is writing the text, the subject, the person to who is addressed and than press "send".
    I often forget to check the "from", and this is a problem because the software select itself one of the accounts.
    Isn't there a way at least to put as a default a blank field instead of one of the accounts? or an account which doesn't work so if I forget to specify the "from" I will be rnotofied that the message can't be sent.
    I guess this could be a rather common problem for many people!
    Thanks
    Sergio

  • Sender jms adapter-archiving before processing the message

    Hi,
    Do we have any option in Sender JMS adapter to archive the message before processing the message?
    I have searched in sender JMS adapter (XI7.0) settings, but couldn't find any option.
    My assumption is whether any option provided in configuration setting of adapter engine or any other alternatives.
    Thanks,
    Srini.

    Hi Srini.
    Here is the code. But you may prefer the EAR module, just for deploy. I need your email to send it to you.
    If you want to create it yourself follow the steps in this guide and paste the code:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f013e82c-e56e-2910-c3ae-c602a67b918e
    When you configure the module in the JMS sender communication channel you have to spedify 2 parameter for the log file location:
    "file.path" (XI server file system path) and "file.name"
    CODE:
    package com.bfa.af.modules;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Date;
    import javax.ejb.CreateException;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    import com.sap.aii.af.mp.module.Module;
    import com.sap.aii.af.mp.module.ModuleContext;
    import com.sap.aii.af.mp.module.ModuleData;
    import com.sap.aii.af.mp.module.ModuleException;
    import com.sap.aii.af.ra.ms.api.Message;
    @author ibermatica
    public class BFATraceModule implements SessionBean, Module {
         private SessionContext myContext;
         public void ejbRemove() {
         public void ejbActivate() {
         public void ejbPassivate() {
         public void setSessionContext(SessionContext context) {
              myContext = context;
         public void ejbCreate() throws CreateException {
         public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData) throws ModuleException
              FileWriter outFile;
              try
                   Date date = new Date();
                   String filePath = moduleContext.getContextData("file.path");
                   String fileName = moduleContext.getContextData("file.name");
                   outFile = new FileWriter(filePath + System.getProperty("file.separator") + fileName, true);
              catch (IOException e)
                   e.printStackTrace();
                   throw new ModuleException(e);
              PrintWriter out = new PrintWriter(outFile, true);
              try
                   out.println("--- Start of message ---");
                   //Get message content.
                   Message data = (Message)inputModuleData.getPrincipalData();
                   if(data.getDocument() != null)
                        out.println(data.getDocument().getText());
                   else
                        out.println("Empty message.");
                   out.println("--- End of message ---");
                   out.println("Total characters: " + data.getDocument().getText().length());
              catch(Exception exc)
                   out.println(exc.toString());
              finally
                   if(out != null)
                        out.close();     
                   if(outFile != null)
                        try {
                             outFile.close();
                        } catch (IOException e1) {
                             throw new ModuleException(e1);
              return inputModuleData;

  • FTP sender adapter wait sometime before processing a message

    Hi,
    I want my FTP sender adapter to wait sometime before processing a message. This is needed in my case since the receiver of the message cannot consume message in, say two seconds, so I would like to configure a "time to wait before processing message" in PI since PI processes all of the files in folder without waiting another poll interval time if more than one exist.
    Is this possible in PI 7.0 sp16? 
    Regards,

    HI Tarik
    BPM is the solution for this problem. If you are not willing to use BPM other solutions are  Adapter module and Scripts
    You can write adapter module and use the threads mechanism. Thread.sleep can help you achieve this but you need to set this properly.
    Another method is Unix script. Let your actual directory be Dir1 and poll PI to Dir2. Use the script to write files from Dir1 to Dir2 one by one and with time gap. This will work for you.
    If you have PI system on Windows i prefer to go with Adapter module.
    Thanks
    Gaurav

  • On my iPhone 5, can I set a preference to ask if I want to send a message that has misspelled words before it's sent?

    The spell checker correctly shows a red underline to flag misspelled words. However, sometimes I miss them or inadvertently send the message before I've checked (new user, not sure how this happens). Is there a way to have a question box show up to ask me if I'm ready to send with spelling errors? I did find some guidance in prior questions to the Community but they were for other Apple i products.

    Not that I have found. The interface apparently expects you to correct them the moment they occur. A PITA, if you ask me, since it breaks the typing rythmn.

  • How do I edit the font and bold text in the message box in adobe send before sending to client?

    How do I edit the font and bold text in the message box in adobe send before sending to client?

    Hi BRAEWOOD DEVELOPMENTS,
    You can edit the Subject & Message when you've selected Send Personalized Invitations (though you can't change the font or style of the text).
    Best,
    Sara

Maybe you are looking for

  • Documentation generator

    Hi. What documentation generator was used for Adobe Flex Language Reference ? I have got into the habit with this style of docs, and I want to make my docs look so.

  • Cursor freezes, cursor freezes

    Has anyone found a solution to  system freezing at stratiup after upgrading to Mavericks?

  • Lightroom won't install

    I am a creative cloud member, trying to download lightroom, and getting the following message when I do: "Adobe Genuine Software Failure. The product you are trying to install is not an Adobe Genuine Software and appears to be counterfeit." How is th

  • Need to open database

    I've been given a supposed Oracle database with an extension of .DB Additional files provided to me had extensions of .bi .lg and .lic I don't work in an Oracle database environment, but need to extract the data for import to SQL tables. Are these Or

  • How to see the full program on the front panel when it is running?

    Hi, my program is really big, and when I run it and obverserve the program on the front panel, I cannot drag the window to see the other parts. Also, I tried the method like hold control, then press + to zoom in or press - to zoom out. However, labvi