Monitor serial port output
LegacyUser
Posts: 0
in AMX Hardware
Is there a command line function that I could run which would monitor the output of one of the serial ports on an NI-3000? I'm having a hell of a time troubleshooting a serial device that just wont work and it would be useful to see exactly what the NI thinks it is sending that device while the device is actually connected to the serial port.
-Jim
-Jim
0
Comments
Diagnostics does indeed do a poor job but Notifications (the one I suggested) does a good job with unprintable characters as it converts them to their 2 digit hex code. It also doesn?t choke on NULLS like Diagnostics does. I?ve used Notifications extensively for troubleshooting and monitoring serial controlled devices and have had good success. But you do need to be careful with how many devices are enabled for Notifications because enough traffic will make Netlinx Studio crash.
Third-party software is a great help for initial testing of a serial controlled device (it sure beats the heck out of Hyper Terminal) but once you get to the stage of having to monitor traffic between the NI-3000 and the controlled device I?m not sure how it helps. If I?m missing something please let me know.
One other thing worth mentioning: If you?re sending data but not getting any data back from the device (and you know the baud rate is correct and the cabling is correct) make sure you have CREATE_BUFFER in DEFINE_START, or have a STRING handler present in the DATA_EVENT of the controlled device, or manually do an RXON someplace in your code so that the NI comm port is enabled to receive data.
In situations like that, I find it helpful to not have the device connected to isolate my own part of the transaction and make sure it's correct.
Serial port troubleshooting can be tuff sometimes. I verify cable connection using the code below and a 9 pin plug with pins 2-3 shorted as a quick test. This wont tell you if have 2 and 3 are crossed wrong or shorted, but you willl not get result if one of those two pins is shorted to pin 5, your cable length is way too long or there is interference from something else. If the situation is right, relay 1 will turn on and off while the short is in place and you don't need anything more than to look at the led on the front of the contoller to verify it.
If it is a long run. 50' or more (75' limit?) consider lowering the buad rate, using a RS422 converter and using RS422 on the controllers. I have seen some devices work better than others at the same range. Problems related to cable length usually present themselves with commands and responses getting garbeled over distance. You can use the same code with netlinx diagnostics by connecting to the controller, setting up device notifications, Turn on strings to and from the device (Make sure your system number is the right number, not "0" or it wont work. - IE 5001:1:65535). View the notifications tab. What you send down that cable length should come back exactly the same.
Another method - Hopefully you can query the device. After setting up notification options, Choose control a device. In the case of com1 on a 3000 with system number 1, send 5001:1:1 something like "'pwr?'" or whatever the protocol manual says. Are you getting the right response back? If you are, maybe your program needs some work.
Or send a "command" directly to the port like "'GET BAUD'" You should get the baud rate back. Did your baud rate get set correctly at online?
Here is the code below good luck.
DEFINE_DEVICE
serialport1 = 5001: 1:0
relay = 5001: 8:0
DEFINE_CONSTANT // create a string as long as you want
teststring[] = {$03,$95,$00,$00,$00,$98}
//or teststring = "'I hate troubleshooting RS232 problems!'"
DEFINE_VARIABLE
Serial
send
DEFINE_START
serial = 0
DEFINE_EVENT
DATA_EVENT[serialport1]
{
ONLINE :
{
// check any buad rate you want
SEND_COMMAND DATA.DEVICE,"'SET BAUD 9600,N,8,1 485 DISABLED'"
SEND_COMMAND DATA.DEVICE,"'HSOFF'"
}
STRING :
{
IF(FIND_STRING(DATA.TEXT, teststring, 1))
{
if( [relay,1] = 0 )
ON[relay,1]
else
OFF[relay, 1]
}
}
}
DEFINE_PROGRAM
WAIT 10
{
SEND_STRING serialport1, teststring
}
The actual max distances can vary drastically depending on the cabling being used. It has been discussed here: http://amxforums.com/showthread.php?t=1663
If you run at 9600 baud, you should be able to get 500ft on CAT5.
Jeff
What I wrote is based upon 18 years of experience with rs232 interfaces. running 500ft of cat5 cable at 9600 is a bad idea. The EIA standard is 50 feet, OR a cable length equal to a capacitance of 2500 pF. UTP CAT-5 cable is typically 17 pF/ft, therefore the EIA standard for that cable would be 147 feet in a perfect environment with perfect equipment. I have seen that same cable fail (garbeled data) at 9600 baud at 50' between a NI-2000 and a MT1065 projector in our engineering physics building. Normally we do not use cat 5 for rs232, but the building design required we used existing cabling and tested the run with a very expensive TDA.
AMX has set their standard as follows. RS232 - 50 feet, RS422/485 - 4000 feet. Following those standards will save a person a lot of trouble down the road.
Joe