Thread Device::SerialPort und lcd programmierung (Ezio) (17 answers)
Opened by mark05 at 2011-11-03 16:44

mark05
 2011-11-03 16:44
#153818 #153818
User since
2010-01-05
129 Artikel
BenutzerIn
[default_avatar]
hi

da ich leider nicht der grosse C mogel bin und ich von dem am seriellen
port angeschlossen LCD display keinen muks raus bekomme die frage was
mache ich verkehrt.

hier mal der aktuelle perl code.
ich habe auch nocht vom hersteller den C-Code

c-code

danke schon mal

holger
p.s. der perl code ist erstmal nur funktion test ... sprich spielwiese

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;
use Device::SerialPort ;#qw( :PARAM :STAT 0.07 );
my $PortObj ;

use bytes;

my $ezio = {
                cmd=> chr hex ( '0xFE' ),
                init=> chr hex ( '0x28' ),
                stopsend=>chr hex ( '0x37' ),
                cls=> chr ( 1 ) ,
                home=> chr ( 2 ),
                blank=> chr  ( 8 ),
                hide=>chr hex ( '0x0C' ),
};
sub ShowMessage {
my $text = shift;
my $text2 = shift;

use bytes ;

my $textlength = length $text;
my $textlength2 = length $text2;
no bytes;
my $textpos = 40 - $textlength;

#print "$textpos\n";

$PortObj->write("$text");
$PortObj->write("$text,$textlength");
$PortObj->write(q{},$textpos);
$PortObj->write($text2,$textlength2);

#print FH $text,$textlength;
#print FH q{},$textpos;
#print FH $text2,$textlength2;

return ()
}
sub SerialInit {
        $PortObj = Device::SerialPort->new ( '/dev/cua01' ) || die "Can't open serialport: $!\n";
        $PortObj->datatype('raw');  
        $PortObj->user_msg(1);       # built-in instead of warn/die above
        $PortObj->error_msg(1);      # translate error bitmasks and carp
        #$PortObj->debug(1);
        $PortObj->baudrate(2400);
        $PortObj->parity('none');
        $PortObj->databits(8);
        $PortObj->stopbits(1);
        $PortObj->purge_all();
#        $PortObj->dtr_active(1);
#        $PortObj->rts_active(0);
# $PortObj->save('/tmp/settings.cua01');
# $PortObj->close();

        return ();
}

sub Uninit_Serial {
 $PortObj->close();
 return ();
}

sub Init {
 $PortObj->write("$ezio->{cmd}");
 $PortObj->write("$ezio->{init}");
 $PortObj->write("$ezio->{cmd}");
 $PortObj->write("$ezio->{init}");
 return ();
}

sub Cls {
 $PortObj->write("$ezio->{cmd}");          # initial prompt
 $PortObj->write("$ezio->{cls}");          # initial prompt
 return ();
}


SerialInit ;
Uninit_Serial();
SerialInit();
Init();
Cls();


ShowMessage('*Portwell EZIO *','****************');

Uninit_Serial();

1;


serial.h
more (21.2kb):
Code (c): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include        <stdlib.h>
#include        <termios.h>
#include        <unistd.h>
#include        <fcntl.h>
#include        <errno.h>
#include        <ctype.h>
#include        <stdio.h>

#define FALSE   0
#define TRUE    1

// serial device name
const char *serial_port_names[]=
        {"ttyS0", "ttyS1", "ttyS2", "ttyS3", "ttyS4",
        "ttyS5", "ttyS6", "ttyS7", "ttyS8", "ttyS9"};

// com port handle
int fd;

//------------------------------------------------------------------------------
int Serial_Init(int port, int baud_rate)
{
        char devname[512];
        int brate;
        struct termios term; 

        //make device name string
        sprintf(devname, "/dev/%s", serial_port_names[port]);
        
        //open device
        fd = open(devname, 2);
        if (fd <= 0)
        {
                //error opening port
                printf("unable to open device\n");
                return(1);
        }

        //get baud rate
        switch (baud_rate)
        {
                case 1200:
                        brate=B1200;
                        break;
                case 1800:
                        brate=B1800;
                        break;
                case 2400:
                        brate=B2400;
                        break;
                case 4800:
                        brate=B4800;
                        break;
                case 9600:
                        brate=B9600;
                        break;
                case 19200:
                        brate=B19200;
                        break;
                case 38400:
                        brate=B38400;
                        break;
                default:
                        printf("invalid baud rate: %d\n", baud_rate);
                        return(2);
        }

        //get device struct
        if (tcgetattr(fd, &term) != 0)
        {
                printf("tcgetattr failed\n");
                return(3);
        }

        //input modes 
        term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL
                        |IUCLC|IXON|IXANY|IXOFF|IMAXBEL);
        term.c_iflag |= IGNPAR;

        //output modes 
        term.c_oflag &= ~(OPOST|OLCUC|ONLCR|OCRNL|ONOCR|ONLRET|OFILL
                        |OFDEL|NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
        term.c_oflag |= NL0|CR0|TAB0|BS0|VT0|FF0;

        //control modes
        term.c_cflag &= ~(CSIZE|PARENB|CRTSCTS|PARODD|HUPCL);
        term.c_cflag |= CREAD|CS8|CSTOPB|CLOCAL;

        //local modes 
        term.c_lflag &= ~(ISIG|ICANON|IEXTEN|ECHO|FLUSHO|PENDIN);
        term.c_lflag |= NOFLSH;

        //set baud rate
        cfsetospeed(&term, brate);
        cfsetispeed(&term, brate);

        //set new device settings
        if (tcsetattr(fd, TCSANOW, &term)  != 0)
        {
                printf("tcsetattr failed\n");
                return(4);
        }
}

void Uninit_Serial()
{
        close(fd);
        fd=(int)NULL;
}


icon.h
more (82.8kb):
Code (c): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/* Setting icon */
int icon1[] = { 64,0x02,65,0x06,66,0x0F,67,0x1F,
               68,0x0F,69,0x06,70,0x02,71,0x00 };
int icon2[] = { 72,0x02,73,0x06,74,0x0F,75,0x1F,
               76,0x0F,77,0x06,78,0x02,79,0x00 };
int icon3[] = { 80,0x02,81,0x06,82,0x0F,83,0x1F,
               84,0x0F,85,0x06,86,0x02,87,0x00 };
int icon4[] = { 88,0x02,89,0x06,90,0x0F,91,0x1F,
               92,0x0F,93,0x06,94,0x02,95,0x00 };
int icon5[] = { 96,0x02,97,0x06,98,0x0F,99,0x1F,
               100,0x0F,101,0x06,102,0x02,103,0x00 };
int icon6[] = { 104,0x02,105,0x06,106,0x0F,107,0x1F,
               108,0x0F,109,0x06,110,0x02,111,0x00 };
int icon7[] = { 112,0x02,113,0x06,114,0x0F,115,0x1F,
               116,0x0F,117,0x06,118,0x02,119,0x00 };
int icon8[] = { 120,0x02,121,0x06,122,0x0F,123,0x1F,
               124,0x0F,125,0x06,126,0x02,127,0x00 };
    
/* Init Icon Function */
void init_icon1() {
  
  write(fd,&Cmd,1);
  write(fd,&icon1[0],1);
  write(fd,&icon1[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[2],1);
  write(fd,&icon1[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[4],1);
  write(fd,&icon1[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[6],1);
  write(fd,&icon1[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[8],1);
  write(fd,&icon1[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[10],1);
  write(fd,&icon1[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[12],1);
  write(fd,&icon1[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[14],1);
  write(fd,&icon1[15],1);
}

void init_icon2() {
  
  write(fd,&Cmd,1);
  write(fd,&icon2[0],1);
  write(fd,&icon2[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[2],1);
  write(fd,&icon2[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[4],1);
  write(fd,&icon2[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[6],1);
  write(fd,&icon2[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[8],1);
  write(fd,&icon2[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[10],1);
  write(fd,&icon2[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[12],1);
  write(fd,&icon2[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[14],1);
  write(fd,&icon2[15],1);
}


void init_icon3() {
  
  write(fd,&Cmd,1);
  write(fd,&icon3[0],1);
  write(fd,&icon3[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[2],1);
  write(fd,&icon3[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[4],1);
  write(fd,&icon3[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[6],1);
  write(fd,&icon3[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[8],1);
  write(fd,&icon3[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[10],1);
  write(fd,&icon3[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[12],1);
  write(fd,&icon3[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[14],1);
  write(fd,&icon3[15],1);
}


void init_icon4() {
  
  write(fd,&Cmd,1);
  write(fd,&icon4[0],1);
  write(fd,&icon4[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[2],1);
  write(fd,&icon4[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[4],1);
  write(fd,&icon4[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[6],1);
  write(fd,&icon4[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[8],1);
  write(fd,&icon4[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[10],1);
  write(fd,&icon4[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[12],1);
  write(fd,&icon4[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[14],1);
  write(fd,&icon4[15],1);
}


void init_icon5() {
  
  write(fd,&Cmd,1);
  write(fd,&icon5[0],1);
  write(fd,&icon5[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[2],1);
  write(fd,&icon5[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[4],1);
  write(fd,&icon5[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[6],1);
  write(fd,&icon5[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[8],1);
  write(fd,&icon5[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[10],1);
  write(fd,&icon5[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[12],1);
  write(fd,&icon5[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[14],1);
  write(fd,&icon5[15],1);
}


void init_icon6() {
  
  write(fd,&Cmd,1);
  write(fd,&icon6[0],1);
  write(fd,&icon6[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[2],1);
  write(fd,&icon6[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[4],1);
  write(fd,&icon6[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[6],1);
  write(fd,&icon6[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[8],1);
  write(fd,&icon6[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[10],1);
  write(fd,&icon6[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[12],1);
  write(fd,&icon6[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[14],1);
  write(fd,&icon6[15],1);
}


void init_icon7() {
  
  write(fd,&Cmd,1);
  write(fd,&icon7[0],1);
  write(fd,&icon7[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[2],1);
  write(fd,&icon7[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[4],1);
  write(fd,&icon7[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[6],1);
  write(fd,&icon7[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[8],1);
  write(fd,&icon7[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[10],1);
  write(fd,&icon7[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[12],1);
  write(fd,&icon7[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[14],1);
  write(fd,&icon7[15],1);
}


void init_icon8() {
  
  write(fd,&Cmd,1);
  write(fd,&icon8[0],1);
  write(fd,&icon8[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[2],1);
  write(fd,&icon8[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[4],1);
  write(fd,&icon8[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[6],1);
  write(fd,&icon8[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[8],1);
  write(fd,&icon8[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[10],1);
  write(fd,&icon8[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[12],1);
  write(fd,&icon8[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[14],1);
  write(fd,&icon8[15],1);
}

/* Initial all icon */
init_all_icon () {
  init_icon1();
  init_icon2();
  init_icon3();
  init_icon4();
  init_icon5();
  init_icon6();
  init_icon7();
  init_icon8();
  Cls();
}

/* Call icon i from 0 to 7 */
void show_icon(int i){

  write(fd,&i,1);
}


command.h
more (101.6kb):
Code (c): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
int Cmd = 0xFE ;  /* EZIO Command */
void Cls () { 
int cls = 1 ;    /* Clear screen */
  write(fd,&Cmd,1);
  write(fd,&cls,1);     
}

int init = 0x28 ; /* Initialize EZIO */ 
void Init () {
  write(fd,&Cmd,1);
  write(fd,&init,1);    
  write(fd,&Cmd,1);
  write(fd,&init,1);    
}

int stopsend = 0x37 ; /* Stop sending any data to EZIO */
void StopSend () {
  write(fd,&Cmd,1);
  write(fd,&init,1);    
}

int home = 0x2 ; /* Home cursor */
void Home () {
  write(fd,&Cmd,1);
  write(fd,&home,1);
}
        
int readkey = 0x6 ; /* Read key */
void ReadKey () {
  write(fd,&Cmd,1);
  write(fd,&readkey,1);
}

int blank = 0x8 ; /* Blank display */
void Blank () {
  write(fd,&Cmd,1);
  write(fd,&blank,1);
}

int hide = 0x0C ; /* Hide cursor & display blanked characters */
void Hide () {
  write(fd,&Cmd,1);
  write(fd,&hide,1);
}

int turn = 0x0D ; /* Turn On (blinking block cursor) */
void TurnOn () {
  write(fd,&Cmd,1);
  write(fd,&turn,1);
}

int show = 0x0E ; /* Show underline cursor */
void Show () {
  write(fd,&Cmd,1);
  write(fd,&show,1);
}

int movel = 0x10 ; /* Move cursor 1 character left */
void MoveL () {
  write(fd,&Cmd,1);
  write(fd,&movel,1);
}

int mover = 0x14 ; /* Move cursor 1 character right */
void MoveR () {
  write(fd,&Cmd,1);
  write(fd,&mover,1);
}

int scl = 0x18 ; /* Scroll cursor 1 character left */
void ScrollL(){
  write(fd,&Cmd,1);
  write(fd,&scl,1);
}

int scr = 0x1C ; /* Scroll cursor 1 character right */
void ScrollR(){
  write(fd,&Cmd,1);
  write(fd,&scr,1);
}

int address = 0x84F; /* Set cursor address from 0x80 to 0x8F, 0x840 to 0x84F */
void SetAddress () {
  write(fd,&Cmd,1);
  write(fd,&address,1);
}
icon.h
[more][code=c]/* Setting icon */
int icon1[] = { 64,0x02,65,0x06,66,0x0F,67,0x1F,
               68,0x0F,69,0x06,70,0x02,71,0x00 };
int icon2[] = { 72,0x02,73,0x06,74,0x0F,75,0x1F,
               76,0x0F,77,0x06,78,0x02,79,0x00 };
int icon3[] = { 80,0x02,81,0x06,82,0x0F,83,0x1F,
               84,0x0F,85,0x06,86,0x02,87,0x00 };
int icon4[] = { 88,0x02,89,0x06,90,0x0F,91,0x1F,
               92,0x0F,93,0x06,94,0x02,95,0x00 };
int icon5[] = { 96,0x02,97,0x06,98,0x0F,99,0x1F,
               100,0x0F,101,0x06,102,0x02,103,0x00 };
int icon6[] = { 104,0x02,105,0x06,106,0x0F,107,0x1F,
               108,0x0F,109,0x06,110,0x02,111,0x00 };
int icon7[] = { 112,0x02,113,0x06,114,0x0F,115,0x1F,
               116,0x0F,117,0x06,118,0x02,119,0x00 };
int icon8[] = { 120,0x02,121,0x06,122,0x0F,123,0x1F,
               124,0x0F,125,0x06,126,0x02,127,0x00 };
    
/* Init Icon Function */
void init_icon1() {
  
  write(fd,&Cmd,1);
  write(fd,&icon1[0],1);
  write(fd,&icon1[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[2],1);
  write(fd,&icon1[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[4],1);
  write(fd,&icon1[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[6],1);
  write(fd,&icon1[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[8],1);
  write(fd,&icon1[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[10],1);
  write(fd,&icon1[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[12],1);
  write(fd,&icon1[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon1[14],1);
  write(fd,&icon1[15],1);
}

void init_icon2() {
  
  write(fd,&Cmd,1);
  write(fd,&icon2[0],1);
  write(fd,&icon2[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[2],1);
  write(fd,&icon2[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[4],1);
  write(fd,&icon2[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[6],1);
  write(fd,&icon2[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[8],1);
  write(fd,&icon2[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[10],1);
  write(fd,&icon2[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[12],1);
  write(fd,&icon2[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon2[14],1);
  write(fd,&icon2[15],1);
}


void init_icon3() {
  
  write(fd,&Cmd,1);
  write(fd,&icon3[0],1);
  write(fd,&icon3[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[2],1);
  write(fd,&icon3[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[4],1);
  write(fd,&icon3[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[6],1);
  write(fd,&icon3[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[8],1);
  write(fd,&icon3[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[10],1);
  write(fd,&icon3[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[12],1);
  write(fd,&icon3[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon3[14],1);
  write(fd,&icon3[15],1);
}


void init_icon4() {
  
  write(fd,&Cmd,1);
  write(fd,&icon4[0],1);
  write(fd,&icon4[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[2],1);
  write(fd,&icon4[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[4],1);
  write(fd,&icon4[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[6],1);
  write(fd,&icon4[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[8],1);
  write(fd,&icon4[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[10],1);
  write(fd,&icon4[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[12],1);
  write(fd,&icon4[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon4[14],1);
  write(fd,&icon4[15],1);
}


void init_icon5() {
  
  write(fd,&Cmd,1);
  write(fd,&icon5[0],1);
  write(fd,&icon5[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[2],1);
  write(fd,&icon5[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[4],1);
  write(fd,&icon5[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[6],1);
  write(fd,&icon5[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[8],1);
  write(fd,&icon5[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[10],1);
  write(fd,&icon5[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[12],1);
  write(fd,&icon5[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon5[14],1);
  write(fd,&icon5[15],1);
}


void init_icon6() {
  
  write(fd,&Cmd,1);
  write(fd,&icon6[0],1);
  write(fd,&icon6[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[2],1);
  write(fd,&icon6[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[4],1);
  write(fd,&icon6[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[6],1);
  write(fd,&icon6[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[8],1);
  write(fd,&icon6[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[10],1);
  write(fd,&icon6[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[12],1);
  write(fd,&icon6[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon6[14],1);
  write(fd,&icon6[15],1);
}


void init_icon7() {
  
  write(fd,&Cmd,1);
  write(fd,&icon7[0],1);
  write(fd,&icon7[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[2],1);
  write(fd,&icon7[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[4],1);
  write(fd,&icon7[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[6],1);
  write(fd,&icon7[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[8],1);
  write(fd,&icon7[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[10],1);
  write(fd,&icon7[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[12],1);
  write(fd,&icon7[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon7[14],1);
  write(fd,&icon7[15],1);
}


void init_icon8() {
  
  write(fd,&Cmd,1);
  write(fd,&icon8[0],1);
  write(fd,&icon8[1],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[2],1);
  write(fd,&icon8[3],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[4],1);
  write(fd,&icon8[5],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[6],1);
  write(fd,&icon8[7],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[8],1);
  write(fd,&icon8[9],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[10],1);
  write(fd,&icon8[11],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[12],1);
  write(fd,&icon8[13],1);
  write(fd,&Cmd,1);
  write(fd,&icon8[14],1);
  write(fd,&icon8[15],1);
}

/* Initial all icon */
init_all_icon () {
  init_icon1();
  init_icon2();
  init_icon3();
  init_icon4();
  init_icon5();
  init_icon6();
  init_icon7();
  init_icon8();
  Cls();
}

/* Call icon i from 0 to 7 */
void show_icon(int i){

  write(fd,&i,1);
}


ezio.c
more (23.0kb):
Code (c): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "serial.h"
#include "command.h"
#include "icon.h"
#include "string.h"

#define VERSION "2.0"

//com port. 0=COM1 or ttyS0
#define COMPORT 1 
//baud rate
#define BAUD 2400



/* Add or Change Show Message here */
char mes1[] = "*Portwell EZIO *";
char mes2[] = "****************";
char mes3[] = "Up is selected";
char mes4[] = "Down is selected";
char mes5[] = "Ent is selected";
char mes6[] = "ESC is selected";
char mes7[] = "Opt1 is selected"; 
char nul[] = "                                       ";

int a,b;
void ShowMessage (char *str1 , char *str2) {
   a = strlen(str1);
   b = 40 - a;
   write(fd,str1,a);
   write(fd,nul,b);
   write(fd,str2,strlen(str2));
}

int main(int argc, char* argv[]) {

   fprintf(stderr,"Portwell Inc. EZIO command-line communications sample " VERSION"\n"); 
   Serial_Init(COMPORT, BAUD);  /* Initialize RS-232 environment */ 
   Uninit_Serial();
   Serial_Init(COMPORT, BAUD);
   Init();                      /* Initialize EZIO */
   Cls();                       /* Clear screen */
   init_all_icon();             /* Initialize all icon */
   ShowMessage(mes1,mes2);

   while (1) {                  
     int res;
     unsigned char buf[255];
     
     ReadKey(); /* sub-routine to send "read key" command */
     res = read(fd,buf,255); /* read response from EZIO */
     printf("0=%2X, 1=%2X\n", buf[0],buf[1]);
     
     switch(buf[1]) {        /* Switch the Read command */
     
            case 0xbe :         /* Up Botton was received */
                       Cls();
                   ShowMessage(mes1,mes3); /** display "Portwell EZIO" */
                   break;                  /** display "Up is selected */

        case 0xbd :     /** Down Botton was received */
                   Cls();
                   ShowMessage(mes1,mes4);  /** display "Portwell EZIO" */
                   break;                   /** display "Down is selected" */
         
        case 0xbb :     /** Enter Botton was received */
                   Cls();
                   ShowMessage(mes1,mes5);  /** display "Portwell EZIO" */
                   break;                   /** display "Enter is selected" */
             
        case 0xb7 :     /** Escape Botton was received */
                   Cls();
                   ShowMessage(mes1,mes6);  /** display "Portwell EZIO" */
                   break;                   /** display "Escape is selected */
                   
        case 0xaf :     /** OPT Botton was received */
                   Cls();
                   ShowMessage(mes1,mes7);  /** display "Portwell EZIO" */
                   break;                   /** display "OPT1 is selected */ 
                   
            case 0x4d :         /* Up Botton was received */
                       Cls();
                   ShowMessage(mes1,mes3); /** display "Portwell EZIO" */
                   break;                  /** display "Up is selected */

        case 0x47 :     /** Down Botton was received */
                   Cls();
                   ShowMessage(mes1,mes4);  /** display "Portwell EZIO" */
                   break;                   /** display "Down is selected" */
         
        case 0x4b :     /** Enter Botton was received */
                   Cls();
                   ShowMessage(mes1,mes5);  /** display "Portwell EZIO" */
                   break;                   /** display "Enter is selected" */
             
        case 0x4e :     /** Escape Botton was received */
                   Cls();
                   ShowMessage(mes1,mes6);  /** display "Portwell EZIO" */
                   break;                   /** display "Escape is selected */
                   
        default:
               
               break; 
       } 
 
  }

  printf("Done.\n\n");
  Uninit_Serial();
  return 0;
 
}


modedit Editiert von GwenDragon: C-Code aus tarball hinzu
Last edited: 2011-11-03 18:56:46 +0100 (CET)

View full thread Device::SerialPort und lcd programmierung (Ezio)