Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/QNX4/SerialPortTest2.cpp

Go to the documentation of this file.
00001 /*
00002   Don't forget to put the Train Controller
00003   to ANALOG = OFF, put it back ON 
00004   if you want to manipulate it manually
00005 */
00006 
00007 #include <j2k/Fred/Basic.hpp>
00008 #include <j2k/Fred/Boolean.hpp>
00009 #include <j2k/Fred/StdTypes.hpp>
00010 #include <j2k/Fred/QNX/System.hpp>
00011 
00012  UINT state;
00013 
00014  pid_t kb_proxy;
00015  pid_t mdm_proxy;
00016  pid_t pid;
00017 
00018  int  kb_fd;
00019  int  mdm_fd;
00020  int  n;
00021  char buf[3];
00022 
00023 void TrainCmd( int cmd ) {
00024   buf[0] = cmd;
00025   write( mdm_fd, &buf, 1 );
00026   delay( 1000 );
00027 }
00028 
00029 void TrainCmd( int cmd, int id ) {
00030   buf[0] = cmd;
00031   buf[1] = id;
00032   write( mdm_fd, &buf, 2 );
00033   delay( 1000 );
00034 }
00035 
00036 int main() {
00037   kb_fd  = open( "/dev/con1",    O_RDWR );  // Local Keyboard
00038   mdm_fd = open( "//2/dev/ser1", O_RDWR );  // QNX-2 Elan104 Board
00039 
00040   kb_proxy  = qnx_proxy_attach( 0, 0, 0, -1 );
00041   mdm_proxy = qnx_proxy_attach( 0, 0, 0, -1 );
00042 
00043   dev_mode( kb_fd,  0, _DEV_MODES );
00044   dev_mode( mdm_fd, 0, _DEV_MODES );
00045 
00046   // Clear, then arm the proxies for future events
00047 
00048   dev_state( kb_fd,  0, _DEV_EVENT_INPUT );
00049   dev_state( mdm_fd, 0, _DEV_EVENT_INPUT );
00050   dev_arm(   kb_fd,  kb_proxy,  _DEV_EVENT_INPUT );
00051   dev_arm(   mdm_fd, mdm_proxy, _DEV_EVENT_INPUT );
00052 
00053   pid = Receive( 0, 0, 0 );
00054 
00055   long function;
00056   printf("\nStart Pgm");
00057   TrainCmd( 96 );
00058 
00059   delay( 500 );
00060 
00061   printf("\nSpeed=9");
00062   TrainCmd( 9, 1 );
00063 
00064   delay( 500 );
00065 
00066   printf("\nReverse=15");
00067   TrainCmd( 15, 1 );
00068 
00069   delay( 500 );
00070 
00071   printf("\nSpeed=13");
00072   TrainCmd( 13, 1 );
00073 
00074   delay( 500 );
00075 
00076   printf("\nStop Train");
00077   TrainCmd( 0,  1 );
00078 
00079   delay( 500 );
00080 
00081   printf("\nStop Pgm");
00082   TrainCmd( 97 );
00083 
00084   return 0;
00085 }

Generated on Sun Oct 14 18:46:42 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001