Difference between revisions of "Scale Communication"

From HiveTool
Jump to: navigation, search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Tips]]
 
[[Category:Tips]]
The hardest part of this project is getting the scale to talk to the computer.  If you are having problems, here are some tips.
+
If a serial port scale is used, perhaps the hardest part of this project is getting the scale to talk to the computer.  If you are having problems, here are some tips.
 +
 
 +
Talking to the scale is straight forward. Usually send a short character string to the scale and listen for a reply. For the Adam Equipment:
 +
 
 +
<pre>
 +
# Set the port to 9600 baud, 8 bit, no parity
 +
stty -F /dev/ttyUSB0 -hupcl ignbrk  -icrnl -ixon -opost  -onlcr -isig -icanon -iexten -echo -echoe -echok  -echoctl -echoke igncr  cs8 -parenb 9600 -parodd
 +
#
 +
# do a quick read to clear any garbage
 +
read -t 0 SCALE < /dev/ttyUSB0
 +
#
 +
# spawn a process that waits a few milliseconds and then sends the command to the scale
 +
# this gives the read command time to start listening
 +
`sleep 0.01;echo -e -n "N\r\n" > /dev/ttyUSB0` &
 +
#
 +
# read the scale but give it plenty of time to respond
 +
read -t 8 SCALE < /dev/ttyUSB0
 +
 
 +
</pre>
 +
 
  
 
== Cable ==
 
== Cable ==
Line 32: Line 51:
 
To talk  to the scale using a terminal emulation program, configure the software so there is no flow control, either hardware or xon/xoff.
 
To talk  to the scale using a terminal emulation program, configure the software so there is no flow control, either hardware or xon/xoff.
  
During initial testing, if trouble is encountered communicating with the scale, it may be useful to set the scale in trn 2 mode so that it continuously transmits data.  It will serve as a signal generator and the data should contiuously scroll across the screen.  This does not confirm that you can talk to the scale, only that the cabling is correct.
+
During initial testing, if trouble is encountered communicating with the scale, it may be useful to set the scale in trn 2 mode so that it continuously transmits data.  It will serve as a signal generator and the data should continuously scroll across the screen.  This does not confirm that you can talk to the scale, only that the cabling is correct.
  
 
== Configuring the computer's serial port ==
 
== Configuring the computer's serial port ==
If the computer you are using (laptop or desktop) has a serial port, a USB/Serial adapter is not necessary. The null modem cable can plug into the serial port on the computer.  They usually map in like /dev/ttyS0.
+
If the computer you are using (laptop or desktop) has a serial port, a USB/Serial adapter is not necessary. The null modem cable can plug into the serial port on the computer.  They usually map in like /dev/ttys.
  
 
On the linux distributions we've tested, the serial port doesn't need configuration.  However, if you have trouble talking to the scale, this is something to try.
 
On the linux distributions we've tested, the serial port doesn't need configuration.  However, if you have trouble talking to the scale, this is something to try.
Line 55: Line 74:
  
  
stty can also  be used to set the serial port parameters:
+
stty can also  be used to set the serial port parameters. If it almost works (ie getting data from the scale but maybe with some garbage characters), try setting the serial port parameters:
If it almost works (ie almost getting back the correct data but maybe with some garbage characters), try setting the serial port parameters:
 
  
 
<pre>
 
<pre>
 
stty -F/dev/ttyS0  -hupcl ignbrk  -icrnl -ixon -opost  -onlcr -isig -icanon -iexten -echo -echoe -echok  -echoctl -echoke igncr
 
stty -F/dev/ttyS0  -hupcl ignbrk  -icrnl -ixon -opost  -onlcr -isig -icanon -iexten -echo -echoe -echok  -echoctl -echoke igncr
 
</pre>
 
</pre>

Latest revision as of 18:21, 22 February 2015

If a serial port scale is used, perhaps the hardest part of this project is getting the scale to talk to the computer. If you are having problems, here are some tips.

Talking to the scale is straight forward. Usually send a short character string to the scale and listen for a reply. For the Adam Equipment:

# Set the port to 9600 baud, 8 bit, no parity
stty -F /dev/ttyUSB0 -hupcl ignbrk  -icrnl -ixon -opost  -onlcr -isig -icanon -iexten -echo -echoe -echok  -echoctl -echoke igncr  cs8 -parenb 9600 -parodd
#
# do a quick read to clear any garbage
read -t 0 SCALE < /dev/ttyUSB0
#
# spawn a process that waits a few milliseconds and then sends the command to the scale
# this gives the read command time to start listening
`sleep 0.01;echo -e -n "N\r\n" > /dev/ttyUSB0` &
#
# read the scale but give it plenty of time to respond
read -t 8 SCALE < /dev/ttyUSB0


Cable

RS-232 Serial Communication Ports

Depending on whether the scale is wired for DTE or DCE, it may require a null modem cable or replacing and rewiring the serial connector.

RS-232 to USB Adapter

If the computer doesn't have a serial port (like the Pi) a USB/RS-232 adapter can be used. They usually map in as /dev/ttyUSB0.

The Prolific chip set has good reviews from the Linux community, but every adapter we've tested has worked fine. Check Amazon

  • Prolific PL2303HX Rev D Chipset RS-232 to USB cable Plugable Technologies

RS-232 (Null Modem) to USB Adapter

This is a little more expensive, but this is a USB/RS-232 adapter with a build in null modem. It should just plug in and work with the Adam CPW200plus.

  • StarTech.com 1 Port USB to Null Modem RS232 DB9 Serial DCE Adapter Cable with FTDI, Black (ICUSB232FTN) [1]

Configuration

Set up the scale. 9600 baud, 8 bit, no parity

Adam Equipment CPWplus200

See Section Section 13 of the CPW200plus User Manual for detailed instructions.

With the scale off, hold the Tare/Zero button and press the On/Off button.

Parameter Setting Rational
Auto Power Off Pr oFF Don't want the scale to turn off after a period of inactivity.
Backlight always off bL 1 Increases battery life when AC power fails.
Baudrate 9600 Default
8 Bit no parity PAr 1 Default
Transmission Mode trn 1 Default. Can set to trn 2 during trouble shooting.

Testing communication

A terminal emulation program like Minicom can be used to test the scale communication.

To talk to the scale using a terminal emulation program, configure the software so there is no flow control, either hardware or xon/xoff.

During initial testing, if trouble is encountered communicating with the scale, it may be useful to set the scale in trn 2 mode so that it continuously transmits data. It will serve as a signal generator and the data should continuously scroll across the screen. This does not confirm that you can talk to the scale, only that the cabling is correct.

Configuring the computer's serial port

If the computer you are using (laptop or desktop) has a serial port, a USB/Serial adapter is not necessary. The null modem cable can plug into the serial port on the computer. They usually map in like /dev/ttys.

On the linux distributions we've tested, the serial port doesn't need configuration. However, if you have trouble talking to the scale, this is something to try.

To list the line parameters for ttyS0: stty -F /dev/ttyS0 -a

Example:

# stty -F /dev/ttyS0 -a    
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V;
flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke


stty can also be used to set the serial port parameters. If it almost works (ie getting data from the scale but maybe with some garbage characters), try setting the serial port parameters:

stty -F/dev/ttyS0  -hupcl ignbrk  -icrnl -ixon -opost  -onlcr -isig -icanon -iexten -echo -echoe -echok  -echoctl -echoke igncr