BS2 and Serial Communication question ...
JMLStamp2p
Posts: 259
Hello,
I am sending serial data into a PDB housed with a BS2 Stamp. I have a O'Scope monitoring
the data and can verify that I am recieving what Im sending. Im using the following code:
RecievedTransmitterData VAR WORD
MAIN:
SERIN 7, 84, [noparse][[/noparse]RecievedTransmitterData]
IF (RevievedTransmitterData = 10) THEN GOTO PumpVoltageOff
' Ect.
' Ect.
' Ect.
GOTO MAIN
The Reciever that Im using sends 1-Start Bit, 8-Data Bits & 1-Stop Bit.
When I DEBUG the incoming data to the screen it shows up as the correct data that Im monitoring
on my Scope. But it appears that the data saved in the varible is being interperated as:
Example: 01101000 as the value "16" that is showing on my scope.
The debug command using the Binary modifier shows as: 00010110 on my computer monitor.
I have written a VB program that is transmitting HEX Data to the reciever but when I try and use:
IF ( HEX RevievedTransmitterData = 10) THEN GOTO PumpVoltageOff
I show getting the value of HEX "10" on my Scope but I get nothing on my monitor.
Am I using the code wrong ?
Thanks for any help,
JMLStamp2p
·
I am sending serial data into a PDB housed with a BS2 Stamp. I have a O'Scope monitoring
the data and can verify that I am recieving what Im sending. Im using the following code:
RecievedTransmitterData VAR WORD
MAIN:
SERIN 7, 84, [noparse][[/noparse]RecievedTransmitterData]
IF (RevievedTransmitterData = 10) THEN GOTO PumpVoltageOff
' Ect.
' Ect.
' Ect.
GOTO MAIN
The Reciever that Im using sends 1-Start Bit, 8-Data Bits & 1-Stop Bit.
When I DEBUG the incoming data to the screen it shows up as the correct data that Im monitoring
on my Scope. But it appears that the data saved in the varible is being interperated as:
Example: 01101000 as the value "16" that is showing on my scope.
The debug command using the Binary modifier shows as: 00010110 on my computer monitor.
I have written a VB program that is transmitting HEX Data to the reciever but when I try and use:
IF ( HEX RevievedTransmitterData = 10) THEN GOTO PumpVoltageOff
I show getting the value of HEX "10" on my Scope but I get nothing on my monitor.
Am I using the code wrong ?
Thanks for any help,
JMLStamp2p
·
Comments
The value you're transmitting is %00010110 in binary, $16 in hexadecimal, and 22 in decimal. There is another encoding called BCD (binary coded decimal) which represents two decimal digits in 8 bits of data with the first decimal digit in the high order 4 bits and the second decimal digit in the low order 4 bits. If you're using this, you'd write the value as $16, but it would be considered the decimal value 16.
When you check ReceivedTransmitterData = 10, you're checking for %00001010 in binary, $0A in hexadecimal, or 10 in decimal. There is no equivalent in BCD (because there's only digits 0 through 9 normally). On the scope, you'd see a start bit (always zero), then the bits 0 1 0 1 0 0 0 0 and the stop bit (always one). Idle on a serial line is a logic high, essentially a continuation of the stop bit.
SERIN 16,16468,[noparse][[/noparse]HEX my_word]
You can then use
SERIN 16,16468,[noparse][[/noparse]HEX my_word]
IF my_word=10 THEN
This example of VB is a test string that takes a value from a text box and converts it to a HEX value. If you type 16 into the text box it is converted to·10h and transmitted.
SerialPort1.WriteLine(Hex(Val(TextBox1.Text)))
Writeline appends a line feed and informs the SERIN that data has ended
Jeff T.
EDIT I am showing the default programming port (16) in your case the pin and baud values would be different
EDIT #2 JML , several hours later and I came back to read what I had written and I see a·mistake. Line two should be IF my_word=$10 THEN
Post Edited (Unsoundcode) : 8/19/2007 1:11:11 AM GMT
After reading your reply's I realized that what I am recieving is an 8- Bit code that
represents two digits. On my scope for some reason the high order Byte or First digit
is intering first so the Binary is "01101000" for the value of "16" on my scope.
When I DEBUG it to the screen it shows up as "00010110" Binary and "16" using the statement: DEBUG HEX RecievedTransmitterData, CR, 13
Mike, It was backwards from what I was expecting. Im using two spread spectrum Transcievers between my Computer and my PDB board.
NOTE: Im sending HEX Data in my Visual Basic program ...
The SERIN Statement Im using is: SERIN 7, 84, [noparse][[/noparse]RecievedTransmitterData]
When I try and use SERIN 7, 84, [noparse][[/noparse]HEX RecievedTransmitterData]
I get nothing on my monitoring screen even though Im sending HEX ???
Jeff, I am learning VB and using Visual Studio 2005. I am also using Franson Serial Tools, are you familiar with them? It seems to be a daunting task to control the serial ports using VB at least for a beginner ! If you are familiar with serial port code using VB wich it seems you are, I could sure use some help :>). This is the code Im using to Transmit HEX data out the port ...
Using "Franson Serial Tools" ...
'...................................................................................................................
Dim port As New SerialNET.Port
port.Enabled = True
Dim binary_data As Byte() = {&H16}
port.Write(SerialNET.Port.ByteArrayToString(binary_data))
objPort_Onwritten(Data)
port.Enabled = False
'...................................................................................................................
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim license As New SerialNET.License()
license.LicenseKey = "License code here"
objPort = New SerialNET.Port()
objPort.BufferSize = 4
port_list = SerialNET.Port.List
init_port_baudrate_dd()
End Sub
'....................................................................................................................
Franson Serial Tools cost only about $35 dollars and seems to work well but the support froum is no where as good as Parallax's.
Thank You,
JMLStamp2p
·
As I mentioned, the Stamp Basic HEX formatter does a printable character to binary conversion on input and binary to hexadecimal human readable conversion on output. It WILL NOT do what you want based on the data you've shown.
Some people refer to what you have as "packed hexadecimal" to indicate that two hexadecimal digits are packed in a byte.
I appreciate the advice, I have never heard anyone refer to "packed hexadecimal" but it seems appropriate. Thats exactly what I am sending and recieving and my recieving program is doing what I need it to do now. You seem to have a very good understanding of code, what languages do you use for programming outside of Basic stamp code?
JMLStamp2p
I do Propeller programming in Spin and assembly. I'm used too many instruction sets and programming languages to remember easily, ranging from Pascal and C more recently to Smalltalk, LISP, Algol, PL360 and others some years ago.
For some reason my O'Scope shows it coming in from the left to the right with the most
significant byte on the right, my trigger symbol being on the Left. I have it triggering on the
falling edge of rreception ...
JMLStamp2p
It's really nice to have the knowledge base to pull from in the Parallax forums. It makes using thier products a lot easier !
Thanks to all who have replied,
JMLStamp2p
Sort of sorry to be a pain, but it's bit, in this case, not byte (a byte is 8 bits.)
Dim binary_data As Byte() = {&H16}
is taking the hex formatted number &H16 and placing it in the binary_data variable as a binary coded decimal number (22) so you are not sending HEX format.
The Stamp will·interperet the byte value as two ascii values (50 50) which we need to convert back to decimal 22.
The format for SERIN would have to be
SERIN 7, 84, [noparse][[/noparse]DEC3 RecievedTransmitterData]
you could then use
IF RecievedTransmitterData=$16 THEN
or
IF RecievedTransmitterData=22 THEN
The formatter DEC3 will accept a value of 0-255 and by using Writeline instead of Write in the VB a LF will be appended allowing the value of binary_data to vary in length otherwise you will have to include leading zeros
Jeff T.