Author Topic: ASCii help needed  (Read 15669 times)

richarddlh

  • Member
  • ***
  • Posts: 4
ASCii help needed
« on: November 23, 2013, 09:56:13 pm »
I am new to the board and need some assistance.  I just purchased a rs232 4 channel relay board on ebay from hong kong.  I have my serial port hooked up correctly using pins 2,3,5 on a db9.  In reading the instructions they sent which was tough as their English is not good.  They say the make code for relay 1 is 0x55 01 01 02 00 00 00 59  How to I get this to work with a program that just sends ascii text strings to the serial port.  Here is the link to the instructions they sent me.  https://docs.google.com/document/d/1XtO0Z6RytXgoOUks6W0QdVszueB60ekZ9-OiA5Nvhb4/edit?usp=sharing&authkey=COf8lCc  They also had me download some bin files and inside them showed 000000: 55 01 01 02 00 00 00 59 u......y  So can anyone help me with this?  I couldn't even get it to do anything in hyperterminal or real terminal.  I know enough to be dangerous with the simple stuff.  Dangerous meaning good or bad at times.  Any help would be awesome.  Thanks...  Richard

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: ASCii help needed
« Reply #1 on: November 23, 2013, 11:51:05 pm »
realterm has a binary option:

http://realterm.sourceforge.net/

Or you can write an application in Visual Basic, C#, etc. to send binary values.

richarddlh

  • Member
  • ***
  • Posts: 4
Re: ASCii help needed
« Reply #2 on: November 24, 2013, 12:07:50 am »
I am just using realterm to test it, but I need it to be a ascii string to work in my other program.  what type of string is that 0x55 01 01 02 00 00 00 59?  does it have something to do with python?  this is where I am lost.  What is the ascii code for that string?

ruutboy

  • Member
  • ***
  • Posts: 19
Re: ASCii help needed
« Reply #3 on: November 24, 2013, 10:17:48 am »
They are giving you hex codes which you will have to translate to ASCII. For instance, 0x55 is "U" in The ASCII table. Any character under 20h (20 hex, or 32 decimal)  isn't going to have a key for it. That goes for a whole bunch of characters north of "z" to boot.

Realterm (apparently, I've never used it. I would do it in basic) will allow you to enter in a string that will get converted to 0x01.  Which for testing purposes will do just fine.

I'm no python programmer, but this might get you started: http://stackoverflow.com/questions/10618586/hex-string-to-character-in-python

ruutboy

  • Member
  • ***
  • Posts: 19
Re: ASCii help needed
« Reply #4 on: November 24, 2013, 07:07:28 pm »
Okay, I checked the docs and here are all of the codes you will have to worry about:

The odd thing is that the checksums that they mention don't seem to be correct (assuming that they are using XOR).


Original:

5501010200000059   Make #1
5501010002000059   Make #2
5501010000020059   Make #3
5501010000000259   Make #4


Instead try this if it doesn't work:

5501010200000057   Make #1
5501010002000057   Make #2
5501010000020057   Make #3
5501010000000257   Make #4


Original:

5501010100000058   Break #1
5501010001000058   Break #2
5501010000010058   Break #3
5501010000000158   Break #4


Instead try this if it doesn't work:

5501010100000054   Break #1
5501010001000054   Break #2
5501010000010054   Break #3
5501010000000154   Break #4


Original:

550101020202025F   Make All
550101010101015B   Break All
5501010000000057   Check Status


Instead try this if it doesn't work:

5501010202020255   Make All
5501010101010155   Break All
5501010000000055   Check Status


And then, just for you, I installed Python and DreamPie and used this snippet of code that I found over at Stack Overflow:

import binascii
binascii.unhexlify(b"55010102000000")

Running this returned:
1: b'U\x01\x01\x02\x00\x00\x00'
>>>

Which is what you are looking for. You would add either the original checksum byte which converts to a 'Y' in ASCII (so the string would end up being: b'U\x01\x01\x02\x00\x00\x00\Y'), or if that didn't work, try: b'U\x01\x01\x02\x00\x00\x00\W'.

import serial

ser = serial.Serial(
    port=COMx',
    baudrate=9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS
)

make1 = "x55\x01\x01\x02\x00\x00\x00\x59"   #use 57 if 59 doesn't work. Heck try them all :)
ser.write(make1)

You can create strings for all of the different makes/breaks and then try them out. (Notice that the 'U' has to be converted to its hex equivalent, aka, the '55')

Keep in mind that my experience in Python started at, oh, about 45 minutes ago. So if (when) it doesn't work... :)

« Last Edit: November 24, 2013, 07:10:08 pm by ruutboy »

richarddlh

  • Member
  • ***
  • Posts: 4
Re: ASCii help needed
« Reply #5 on: November 26, 2013, 01:42:36 am »
Ok, I got it working through realterm.  I can send it in a few ways.  But now I need to get it to work in a program that just send ascii text strings.  The problem I think I have is ASCII 01 = SOH and ASCII 02 = STX.  Is there a way to send the SOH and STX as just plain ASCII text string?  How can you send the control codes as ascii text?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: ASCii help needed
« Reply #6 on: November 26, 2013, 09:28:54 am »
In ASCII text, the values are control codes, not text. So for example, pressing Enter sends a CR code.

What program do you need to use and why do you need to use it? Can you enter data to send only by typing values directly or can edit the source code?

ruutboy

  • Member
  • ***
  • Posts: 19
Re: ASCii help needed
« Reply #7 on: December 02, 2013, 10:13:43 am »
In ASCII text, the values are control codes, not text. So for example, pressing Enter sends a CR code.

What program do you need to use and why do you need to use it? Can you enter data to send only by typing values directly or can edit the source code?

Were the checksums incorrect?

As for converting it to a string, that's what the python example was for in my previous post. You should be able to take the strings from my previous post and use them directly in your code.

What was the reason for choosing python? Do you plan on running this on Linux? Otherwise, I think that you would get more help here if you did it in basic or C.