Skip to content

Commit a3ea09e

Browse files
author
Max Roberg
committed
Adding initial files
1 parent d216e1f commit a3ea09e

13 files changed

Lines changed: 1370 additions & 1 deletion

File tree

631/example-631.c

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// 631_COMMAND_LINE_TEST.cpp
2+
// Ultra-simple 631 command-line communications example
3+
4+
#include <stdio.h>
5+
#include <string.h>
6+
#include <unistd.h>
7+
#include <stdlib.h>
8+
#include "typedefs.h"
9+
#include "serial.h"
10+
#include "cf_packet.h"
11+
#include "show_packet.h"
12+
13+
//============================================================================
14+
int main(int argc, char* argv[])
15+
{
16+
printf("Ultra-simple CFA-631 command-line communications example.\n");
17+
printf("Crystalfontz America, Inc. http://www.crystalfontz.com\n\n");
18+
printf("Usage:\n");
19+
printf("%s PORT BAUD\n",argv[0]);
20+
printf("PORT is something like \"/dev/ttyS0\" or \"/dev/usb/ttyUSB0\"\n");
21+
printf("BAUD is 19200 or 115200\n");
22+
printf("To clear the display, enter \"clear\" as an optional third parameter\n\n");
23+
24+
25+
//If only 0 or 1 parameter is entered, prompt for the missing parameter(s)
26+
if(argc < 3)
27+
{
28+
printf("\nMISSING A PARAMETER. Enter both PORT and BAUD.\n\n");
29+
return(0);
30+
}
31+
32+
//Check for optional "clear" parameter and set flag if found
33+
int
34+
cleardisplay=0;
35+
if((argc > 3) && (!strcmp(argv[3],"clear"))) cleardisplay=1;
36+
37+
38+
int
39+
baud;
40+
//default the baud to 19200
41+
if(strcmp(argv[2],"115200"))
42+
baud=19200;
43+
else
44+
baud=115200;
45+
46+
if(Serial_Init(argv[1],baud))
47+
{
48+
printf("Could not open port \"%s\" at \"%d\" baud.\n",argv[1],baud);
49+
return(1);
50+
}
51+
else
52+
printf("\"%s\" opened at \"%d\" baud.\n\n",argv[1],baud);
53+
54+
//Outgoing command packets. Either clear the screen
55+
//or send our line information
56+
//**********************************************
57+
if(cleardisplay)
58+
{
59+
outgoing_response.command = 6;
60+
outgoing_response.data_length = 0;
61+
send_packet();
62+
}
63+
else
64+
{
65+
//Send line 1 to the 631 using command 31
66+
outgoing_response.command = 31;
67+
outgoing_response.data[0]=0; //col
68+
outgoing_response.data[1]=0; //row
69+
memcpy(&outgoing_response.data[2],"* >This is line 1< *",20);
70+
outgoing_response.data_length = 22;
71+
send_packet();
72+
73+
//CFA-631 / CFA-633 communications protocol only allows
74+
//one outstanding packet at a time. Wait for the response
75+
//packet from the CFA-631 / CFA-633 before sending another
76+
//packet.
77+
int
78+
k;
79+
int
80+
81+
timed_out;
82+
timed_out = 1; //default timed_out is true
83+
for(k=0;k<=10000;k++)
84+
if(check_for_packet())
85+
{
86+
ShowReceivedPacket();
87+
timed_out = 0; //set timed_out to false
88+
break;
89+
}
90+
if(timed_out)
91+
printf("Timed out waiting for a response.\n");
92+
93+
//Send line 2 to the 631 using command 31
94+
outgoing_response.command = 31;
95+
outgoing_response.data_length = 22;
96+
outgoing_response.data[0]=0; //col
97+
outgoing_response.data[1]=1; //row
98+
memcpy(&outgoing_response.data[2],"* >This is line 2< *",20);
99+
send_packet();
100+
101+
//CFA-631 / CFA-633 communications protocol only allows
102+
//one outstanding packet at a time. Wait for the response
103+
//packet from the CFA-631 / CFA-633 before sending another
104+
//packet.
105+
timed_out = 1; //reset timed_out to default false value
106+
for(k=0;k<=10000;k++)
107+
if(check_for_packet())
108+
{
109+
ShowReceivedPacket();
110+
timed_out = 0; //set timed_out to false
111+
break;
112+
}
113+
if(timed_out)
114+
printf("Timed out waiting for a response.\n");
115+
}
116+
//**********************************************
117+
118+
printf("Ctrl-C to exit.\n");
119+
printf("Updated display, now waiting for packets\n\n");
120+
121+
while(!cleardisplay)
122+
{
123+
usleep(100000); // 1/10 second
124+
if(check_for_packet())
125+
ShowReceivedPacket();
126+
}
127+
128+
if(cleardisplay) printf("Display Cleared.\n");
129+
printf("Done.\n\n");
130+
Uninit_Serial();
131+
return 0;
132+
133+
}
134+
//============================================================================

632_634/example-632_634.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// 632_634_COMMAND_LINE_TEST.cpp
2+
// Ultra-simple 632 / 634 command-line communications example
3+
4+
#include <stdio.h>
5+
#include <string.h>
6+
#include <unistd.h>
7+
#include <stdlib.h>
8+
#include "typedefs.h"
9+
#include "serial.h"
10+
11+
//============================================================================
12+
int main(int argc, char* argv[])
13+
{
14+
printf("Ultra-simple CFA-632 / CFA-634 command-line communications example.\n");
15+
printf("Crystalfontz America, Inc. http://www.crystalfontz.com\n\n");
16+
printf("Usage:\n");
17+
printf("%s PORT BAUD\n",argv[0]);
18+
printf("PORT is something like \"/dev/ttyS0\" or \"/dev/usb/ttyUSB1\"\n");
19+
printf("BAUD is 1200, 2400, 4800, 9600 or 19200\n");
20+
printf("To clear the display, enter \"clear\" as an optional third parameter\n\n");
21+
22+
23+
//If only 0 or 1 parameter is entered, prompt for the missing parameter(s)
24+
if(argc < 3)
25+
{
26+
printf("\nMISSING A PARAMETER. Enter both PORT and BAUD.\n\n");
27+
return(0);
28+
}
29+
30+
//Check for optional "clear" parameter and set flag if found
31+
int
32+
cleardisplay=0;
33+
if((argc > 3) && (!strcmp(argv[3],"clear")))
34+
cleardisplay=1;
35+
36+
37+
int
38+
baud;
39+
//default the baud to 19200
40+
if(!strcmp(argv[2],"1200"))
41+
baud=1200;
42+
else
43+
if(!strcmp(argv[2],"2400"))
44+
baud=2400;
45+
else
46+
if(!strcmp(argv[2],"4800"))
47+
baud=4800;
48+
else
49+
if(!strcmp(argv[2],"9600"))
50+
baud=9600;
51+
else
52+
baud=19200;
53+
54+
if(Serial_Init(argv[1],baud))
55+
{
56+
printf("Could not open port \"%s\" at \"%d\" baud.\n",argv[1],baud);
57+
return(1);
58+
}
59+
else
60+
printf("\"%s\" opened at \"%d\" baud.\n\n",argv[1],baud);
61+
62+
63+
//We will try to be tricky, and send out data that will show up correctly
64+
//on both the 634 and 632.
65+
66+
//First turn off "scroll" and "wrap"
67+
SendByte(20);
68+
SendByte(24);
69+
70+
//Write out the bottom two lines
71+
//on the 634. The 632 will ignore
72+
//these lines.
73+
74+
//Position to line 4, col 1
75+
SendByte(17);
76+
SendByte(0);
77+
SendByte(3);
78+
if(cleardisplay==1)
79+
{
80+
//12345678901234567890
81+
SendString(" ");
82+
}
83+
else
84+
{
85+
//12345678901234567890
86+
SendString("This is Line 4 *****");
87+
}
88+
89+
//Position to line 3, col 1
90+
SendByte(17);
91+
SendByte(0);
92+
SendByte(2);
93+
if(cleardisplay==1)
94+
{
95+
//12345678901234567890
96+
SendString(" ");
97+
}
98+
else
99+
{
100+
//12345678901234567890
101+
SendString("This is Line 3 *****");
102+
}
103+
104+
105+
//Write out top two lines of the
106+
//634 and both lines of the 632.
107+
108+
//Position to line 2, col 1
109+
SendByte(17);
110+
SendByte(0);
111+
SendByte(1);
112+
if(cleardisplay==1)
113+
{
114+
//12345678901234567890
115+
SendString(" ");
116+
}
117+
else
118+
{
119+
//12345678901234567890
120+
SendString("This is Line 2 *****");
121+
}
122+
123+
//Position to line 1, col 1
124+
SendByte(17);
125+
SendByte(0);
126+
SendByte(0);
127+
if(cleardisplay==1)
128+
{
129+
//12345678901234567890
130+
SendString(" ");
131+
}
132+
else
133+
{
134+
//12345678901234567890
135+
SendString("This is Line 1 *****");
136+
}
137+
138+
139+
if(cleardisplay==1) printf("Display Cleared.\n");
140+
printf("Done.\n\n");
141+
Uninit_Serial();
142+
return 0;
143+
}
144+
//============================================================================

0 commit comments

Comments
 (0)