Datum Systems PSM-500L Manual do Utilizador Página 56

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 57
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 55
Datum Systems, Inc. PSM-500 Modem Remote Control Protocol
Rev 0.93 12/12/10
B-56
Notes on Creating a Controller Mechanism
I get occasional questions on writing M&C or controllers to talk to and remotely control either the M5 class
or M500 class modems. Here are a few suggestions on making a working controller.
1. The modem returns a response very quickly, usually only a few milli-seconds after the end of your
response message. You have to be ready to accept the response immediately.
2. If you are using a PC running Windows, the COM port must be set to a binary mode and not do
any manipulation of the incoming data. There are no carriage returns or line feeds that would be
used to read a line at a time or an entire response packet.
Linux computers seem to be even more difficult to get into a pure binary character receive mode.
Here is a short snippet showing one way to set the COM1 equivalent in Linux which is “ttyS0”.
The variable “devicename” in this case is a string set to “/dev/ttyS0”. This snippet does not show
any actual operations other than setting up the port.
fd = open(devicename, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd < 0) {
perror("Device could not be opened");
exit(-1);
}
tcgetattr(fd,&oldtio); // save current port settings
// set new port settings for canonical input processing
newtio.c_cflag = B9600 | CS8 | /*STOPBITS | */CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0; //ICANON;
newtio.c_cc[VMIN]=1;
newtio.c_cc[VTIME]=0;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
close(fd);
3. The modem’s processor is an Infineon C166 derivative, and it writes words in classic Intel or any
X86 type “Little-Endian” style. If you are using a controller that is “Big-Endian” like the
Motorola/Freescale processors then the byte order of a variable is reversed and will have to be re-
ordered before evaluating or sending back to the modem.
4. Calculating checksums is not difficult as long as a computer is doing it. Here is a simple “C”
routine to calculate checksums. It could be made considerably simpler, but it has the ability to start
and stop anywhere with a string of characters representing a packet.
/* -----------------------------------------------
Calculates the 8 bit checksum for modem packets
----------------------------------------------- */
static char checksum8 (char *s, char start, unsigned char len)
{
unsigned char i, sum8 = 0;
for (i = 0; i < start + len; i++) {
if (i >= start)
sum8 = (sum8 + s[i]) % 256;
}
return (256 - sum8);
}
5. If you want to define Records or Structures to hold the variables of a particular message, those
variables or the whole structure will normally have to be specified as “Packed”. This is because
most languages will use, for example, a 4 byte integer as their least standard variable size. Packing
should allow you to copy the message data directly into the instance of the structure.
Vista de página 55
1 2 ... 51 52 53 54 55 56 57

Comentários a estes Manuais

Sem comentários