Thanks.
build and send packets (the system specific parts) the example code should get you started. I'm sure there are people here doing this and I haven't for a while, but it wasn't that difficult to do what you need to control IO.
Regards
cww
You can use either Modbus/TCP OR the ASCII UDP commands. Note that these are two different ways of talking to the module. The ASCII commands are listed in the ADAM manual. I've done this in Python using the UDP commands.
I will show some abbreviated code fragments in Python for UDP ASCII with no error handling, and with the application specific code removed.
######################################
First you have to open the socket.
# Open a UDP socket.
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Set the socket time-out.
s.settimeout(IOTimeout)
# Accept UDP datagrams.
s.bind(('', PortNum))
######################################
To read the inputs, you need to send a "read" command to the module.
_IOIP = '10.0.0.1'
# Send ADAM ASCII command to read digital inputs.
s.sendto('$016\r', (_IOIP, PortNum))
# Recieve reply from IO module.
indata, inaddr = s.recvfrom(_BUFFSIZE)
The reply should be exactly 10 characters, and should begin with a '!'. E.g. DI0 = !01000FFE, DI1 = !01000FFD, DI2 = !01000FFB, DI3 = !01000FF7, DI4 = !01000FEF, etc.
Extract last three digits and convert to integer to get the data. Logical results are inverted from actual bit on/off due to the default for the modules being reverse logic.
rawresult=int(indata[6:9], 16)
The code to extract the individual bits is not shown.
######################################
To write to the outputs, first pack the output data into a single integer for each set of 4 bits (not shown).
# Dictionary used to look up output number to ASCII
# commands conversions. This is just the integer to hex ASCII
# method that I used, so don't worry too much about it if you
# don't understand it.
_CMDLIST = {0 : '0', 1 : '1', 2 : '2', 3 : '3', 4 : '4',
5 : '5', 6 : '6', 7 : '7', 8 : '8', 9 : '9',
10 : 'A', 11 : 'B', 12 : 'C', 13 : 'D', 14 : 'E', 15 : 'F'}
_IOIP = '10.0.0.1'
# Send ADAM ASCII command to write digital outputs.
s.sendto('#0100'+_CMDLIST[outdata2]+_CMDLIST[outdata1]+'\r', (_IOIP,
PortNum))
# Receive acknowledge reply from IO module.
ackdata, ackaddr = s.recvfrom(_BUFFSIZE)
# Examine ackdata for errors (not shown).
Successful write commands are (despite what the manual says)
acknowledged with a '!01\r', not a '>\r' (where \r = carriage
return).
######################################
Close the socket when you exit your program.
s.close()
######################################
The code I wrote worked on both Linux and MS-Windows. On MS-Windows though, there was a problem with the OS occasionally claiming port 1025 on boot up for some obscure reason (along with a number of other ports). The 6050 module though actually listens to ports 1024 to 1029 (I don't believe this is documented). I ended up automatically scanning through the list of ports on initialisation to find one that was available. I didn't have this problem with Linux, as Linux
doesn't open up any TCP or UDP ports unless you ask it to (this sort of nonsense is why you need a firewall with MS-Windows).
I am having a similar problem with an ADAM-6017. I used your code, but it does not connect to the ADAM module. I though it was because, when I use s.bind(), I need to send de IP address of the module insead of ''. I do it but it says that the requested address is not valid in its context! Do you have any suggestions as what to do? My understanding is still little on this matter! Thank you so much,
Maria
http://www.control.com/thread/1245191396
Users of this site are benefiting from open source technologies, including PHP, MySQL and Apache. Be happy.
Fortune
Hire the morally handicapped.



