Search the Community
Showing results for tags 'rs232'.
Found 2 results
Hi i need help for communication from/to PC to microchip PIC. i need to send "ADC1xxx" (where xxx is delimiter) to microcontroller via serial port and wait for response (with timeout) i need to send other "commands" and waiting always a response from microcontroller. can anyone help me Yhanks so much
This topic is a complement of therealhanuta´s >CommAPI - Serial and parallel communication with Windows API I think these routines are great, as they are simple to use, and use windows API with NO DLL´s. It is about tips in receiving binary data thru a serial port, including value 0 (=end of string**). I hope it can help someone.. To know about the UDF to read/write serial port, please refer to the above link, with focus at post #3 and over First, what is a binary stream? As an example, a microcontroler (PIC) getting data thru ADC and sending the 2 adquired bytes straight thru serial, without any treatment. Now supose the message has: 1 letter(A-Z) + 4 ADC values + 3 counters of anything (each one byte). Your message will arrive with 1 + 4 x 2 + 3 = 12 bytes (or as AU3 sees it, a "string" with 12 "chars"). $sResult = _CommAPI_ReceiveData($hFile) will have at $sResult a "string" with 12 "chars" ** besides the first one, all other chars have byte values. On them can exist even binary value 0. So, it´s vital that 0 be not interpreted as end of string by receiver (PC) now let´s separate the 1 + 4 + 3 = 8 fields field1= StringMid($sResult,1,1) ;this is just a characte rbetwen A-Z field2= ASC(StringMid($sResult,2,1)) ;LSB of the ADC value. First byte = LSBb, 2nd. byte = MSB field2= field2 + ASC(StringMid($sResult,3,1))*256 ;MSB of ADC => now field2 has LSB + MSB (betwen 0-65535) ;field3..5 are similar to field 2, just increase by one the start position in stringMid field6= ASC(StringMid($sResult,10,1)) ;now field6 a "number" betwen 0-255; ;field7-8 are similar to field 6, just increase by one the start position in stringMid ** - be carefull, as probably $sResult = _CommAPI_ReceiveData($hFile) will get just the chars avaiable at the moment of call, so a kind of test/loop will be necessary to get all them, something like $sResult="" DO $sResult = $sResult & _CommAPI_ReceiveData($hFile) UNTIL stringLentgth($sResult) >= 12 Jose ** thanks Martin into explaining about hex (0) to be interpreted as end-of-string and not xoff.