Version 16 (modified by 3 years ago) ( diff ) | ,
---|
Serial Ports
Using Serial Ports for Linux Shell
By default, the Cardinal 825 ships with the Linux console disabled. To enable it, start the indicator and press 3. Setup Menu. Next, press 4. Update Software Menu and then 3. Settings. If you see console=null, remove that line. Save the settings and reboot your indicator. You will now see Linux output from COM1.
Generic Serial Port Use
The “COM1” and “COM2” serial ports are routed through the main board to the MCF5329 processor on the operator interface board. These ports are controlled by the appropriate uCLinux device driver for the built in Coldfire serial ports. These ports may be accessed as:
/dev/ttyS0 = COM1 /dev/ttyS1 = COM2
For example you may test from the serial terminal by typing:
# echo “Hello” > /dev/ttyS1
This will send the message “Hello” out the COM2 serial port. The 825 COM3 port is connected to the main board MCF5213 processor. If the 825 is configured for OIML operation this port is dedicated to sending OIML format verification weight and may not be used by applications. If OIML is not enabled applications may access the COM3 port by means of the mnbd-comm device driver. For example:
# echo “H313233” > /dev/mnbd
This will output “123” to the COM3 port. Note 31 hexadecimal for the ASCII character “1”, 32 is hexadecimal for the ASCII character “2”, etc. As of kernel 2008-11-20 an additional device file /dev/com3 is provided to simplify COM3 application communications. This additional device file is also controlled by the mnbd-comm device driver.
# echo “123” > /dev/com3
Use of /dev/com3 is deprecated.
This will output “123” to the COM3 port.
To perform a similar operations within a C program you may use code similar to:
This will write to COM2. Note fprintf also allows format specifiers such as %d to be used:
int nID = 240; fprintf(pFile, "ID: %d\r\n", nID);
This would output "ID: 240".
You may want a program that reads the serial port and responds:
This sample displays updating weight on the LCD display and will exit when the Shift-ESC key on the keypad is pressed. If CTRL-F is received on the COM2 port this application will send "ACK received<CR><LF>" out the serial port in response. If CTRL-U is received on the COM2 port this application will send "NACK received<CR><LF>" out the serial port in response. If CTRL-B is received the application will start buffering subsequent received characters. When CTRL-C is received the application will respond back with the buffered characters and stop buffering.
Since COM3 and COM4 are handled by the mainboard processor they allow repeating outputs to be specified with variables for weight, units, etc... This is used by the CScoreboard class in applications such as ID storage. This can be useful because the application can just specify the output and does not have to continue sending constantly.
bool SetMnBdRepeatFormat(void) { g_serial_fmt.fmt = 1; switch(_format) { case FMT_SB500: if(_sbOverCap) { strcpy((char*)g_serial_fmt.data, "%%%0 O CAP r\r"); } else { if(_scale == 0) { strcpy((char*)g_serial_fmt.data, "%%%0%G6%%U%G \r"); g_serial_fmt.data[12] = _sbLightCode; } else { sprintf((char*)g_serial_fmt.data, "%%%%%%0%%G(%d)6%%%%U%%G%c\r", _scale, _sbLightCode); } } break; case FMT_COMPIF: strcpy((char*)g_serial_fmt.data, "%G% %U% G %M% \r"); break; case FMT_SB200: strcpy((char*)g_serial_fmt.data, "%G% %U% G %M% \r"); break; case FMT_GENERIC: strcpy((char*)g_serial_fmt.data, "%G% %U% G %M% \r"); break; default: strcpy((char*)g_serial_fmt.data, "%G% %U% G %M% \r"); } g_serial_fmt.len = strlen((char*)g_serial_fmt.data); if(MnBdRequest(MNBD_DEV, MNBD_REQ_SET_SERIAL_FMT, WAIT_ACK) != OK) { _errStr = "Error setting format\r\n"; return false; } else { return true; } } bool Start(void) { _errStr = ""; bool result = false; Stop(); if (_port != 0) { // If COM3 tell mainboard to automatically send output if(_port > 2) { int minor_ver = 0; int ver = GetMnBdVer(&minor_ver); if(ver >= 120 && minor_ver >= 6) { if(SetMnBdRepeatFormat()) { if(_scale == 0) { SetMnBdSerialDefaultScale(0x7F); } g_serial_rep.fmt = 1; g_serial_rep.intv = _interval; if (MnBdRequest(MNBD_DEV + _port - 3, MNBD_REQ_REP_SEND_SERIAL_FMT, WAIT_ACK) != OK) { _errStr = "Error starting scoreboard repeat\r\n"; } else { _mnbdRepeating = true; result = true; } } } else if (ver == 0) { _errStr = "Call MnBdStartup before SB start"; } else { _errStr = "Update MnBd for SB repeating"; } } else { _file.Open(pszCommPortDev[_port], "w"); _timer.Start(_interval, true); result = true; } } return result; }
Variables
%<item code>{(<scale number>)}{<len>}%
{ optional } example %G% = grosswt, %G6% = length 6 characters grosswt, %G(2)6% = length 6 characters scale 2 gross wt
Weight field length may be prefixed with minus sign for left justified negative sign if value is negative. For example %G-6% may produce output such as "- 240". If value is positive a space will be output. Weight field length may be prefixed with a plus sign for left justified plus or minus sign to show positive or negative value. For example %G+6% may produce output such as "+ 50280" or "- 140".
item code | decription |
---|---|
G | Gross weight |
T | Tare weight |
N | Net weight |
U | upper case weight units |
u | lower case weight units |
C | weight status OC=Over Capacity, MO=Motion, BZ=Below Zero, CZ=Center of Zero, two spaces=none of previous |
S | SMA weight status O=Over Capacity, Z=Center of Zero, one space=none of previous |
M | motion status M=Motion, one space=stable |
b | 13 spaces or length specified (MnBd DLC 1.21.023 and above, or MnBd 1.20.016 and above) |
Use three percent characters %%% to output a percent character