-
Notifications
You must be signed in to change notification settings - Fork 3
/
configPIC.c
839 lines (656 loc) · 18.5 KB
/
configPIC.c
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
/**************************************
PIC Multi-Purpose Modbus
configuration application
This program is used to set the Modbus Address of the PIC Multi-purpose module
it will also set the IO pin mode configuration
to compile:
gcc -I /usr/include/modbus configPIC.c -o configPIC -l modbus
libmodbus is needed
please check url: http://libmodbus.org
You could download libmodbus on the Raspberry Pi using
sudo apt-get install libmodbus5 libmodbus-dev
PIC Multi-Purpose configPIC program
Daniel Perron (c) April, 2014
V1.0
***************************************/
//////////////////////////////////// GPL LICENSE ///////////////////////////////////
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <termios.h>
#include <modbus.h>
#include <ctype.h>
#define DEFAULT_DEVICE "/dev/ttyUSB0"
typedef struct
{
unsigned short mode;
unsigned char * asciiMode;
unsigned char SpecialFunctions;
}IOConfigStruct;
char device[256];
int Baud = 9600;
unsigned char scanOnly=0;
unsigned char CurrentSlaveAddress=255;
unsigned char CurrentSlaveId=0;
unsigned char CurrentSlaveIOCount=0;
long timeout=0;
int IsModuleFound(modbus_t * mb, unsigned char SlaveAddress);
unsigned char selectModule(modbus_t * mb);
#define IOCONFIG_ANALOGVDD 0
#define IOCONFIG_ANALOG1V 1
#define IOCONFIG_ANALOG2V 2
#define IOCONFIG_ANALOG4V 3
#define IOCONFIG_INPUT 4
#define IOCONFIG_INPUT_PULLUP 5
#define IOCONFIG_OUTPUT 6
#define IOCONFIG_PWM 7
#define IOCONFIG_CAP_SENSE_OFF 8
#define IOCONFIG_CAP_SENSE_LOW 9
#define IOCONFIG_CAP_SENSE_MEDIUM 10
#define IOCONFIG_CAP_SENSE_HIGH 11
#define IOCONFIG_DHT11 16
#define IOCONFIG_DHT22 17
#define IOCONFIG_DS18B20 32
#define IOCONFIG_SERVO 64
#define IOCONFIG_COUNTER 128
#define IOCONFIG_COUNTER_PULLUP 129
IOConfigStruct configInfo[]={
{ IOCONFIG_ANALOGVDD, "ANALOGVDD",0},
{ IOCONFIG_ANALOG1V, "ANALOG1V",0},
{ IOCONFIG_ANALOG2V, "ANALOG2V",0},
{ IOCONFIG_ANALOG4V, "ANALOG4V",0},
{ IOCONFIG_INPUT, "INPUT",0},
{ IOCONFIG_INPUT_PULLUP, "INPUT PULLUP",1},
{ IOCONFIG_OUTPUT, "OUTPUT",0},
{ IOCONFIG_PWM,"PWM",2},
{ IOCONFIG_CAP_SENSE_OFF, "CAP SENSE OFF",1},
{ IOCONFIG_CAP_SENSE_LOW, "CAP SENSE LOW",1},
{ IOCONFIG_CAP_SENSE_MEDIUM, "CAP SENSE MEDIUM",1},
{ IOCONFIG_CAP_SENSE_HIGH, "CAP SENSE HIGH",1},
{ IOCONFIG_DHT11, "DHT11",1},
{ IOCONFIG_DHT22, "DHT22",1},
{ IOCONFIG_DS18B20, "DS18B20",0},
{ IOCONFIG_SERVO, "R/C SERVO",0},
{ IOCONFIG_COUNTER, "COUNTER",1},
{ IOCONFIG_COUNTER_PULLUP, "COUNTER PULLUP",1},
{65535, "",0}};
unsigned char IsPinHaveSpecialFunctions[]={1,1,1,1,1,0,0,0,0,0};
unsigned char IsPinHavePWM[]= {1,0,0,1,0,0,0,0,1,1};
uint16_t MB_Version;
int moduleID =0;
int GetConfigIndex(int mode)
{
int loop;
for(loop=0;;loop++)
{
if(configInfo[loop].mode== 65535) return -1;
if(configInfo[loop].mode== mode) return loop;
}
return -1;
}
int IsConfigValidOnPin(int mode, int Pin)
{
int configIndex;
if(moduleID == 0) return 0;
if(Pin<0) return 0;
if(mode == IOCONFIG_COUNTER_PULLUP)
{
if(moduleID != 0x653A)
if(Pin>1) return 0;
}
if(Pin>9) return 0;
configIndex = GetConfigIndex(mode);
if(configIndex <0) return 0;
if(mode == IOCONFIG_PWM)
return IsPinHavePWM[Pin];
if(configInfo[configIndex].SpecialFunctions)
if(IsPinHaveSpecialFunctions[Pin]==0)
{
return 0;
}
return 1;
}
char * configModeInText(int IOConfigMode)
{
int loop;
loop = GetConfigIndex(IOConfigMode);
// printf("%03d ",IOConfigMode);
if(loop>=0)
return configInfo[loop].asciiMode;
return "???";
}
void decodeArg(int argc, char * argv[])
{
int loop;
for(loop=1;loop<argc;loop++)
{
if(strcasecmp(argv[loop],"-scan")==0)
scanOnly=1;
if(strcmp(argv[loop],"-d")==0)
{
loop++;
strcpy(device,argv[loop]);
}
if(strcmp(argv[loop],"-b")==0)
{
loop++;
Baud=atoi(argv[loop]);
if(Baud >0)
if(timeout == 0)
{
timeout = (1000000 / Baud)*576;
}
}
if(strcmp(argv[loop],"-t")==0)
{
loop++;
timeout = atol(argv[loop]);
}
if(strcmp(argv[loop],"--help")==0)
{
printf("usage:\nconfigPIC [-scan][-d DeviceName][-b BaudRate] [-t response_Delay_us]\n");
exit(0);
}
}
}
void changeAddress(modbus_t * mb)
{
int new_Address;
printf("\n=======Change Address\n");
if(CurrentSlaveAddress == 255)
selectModule(mb);
else
if(!IsModuleFound(mb,CurrentSlaveAddress))
selectModule(mb);
if(CurrentSlaveAddress==255) return;
printf("\nEnter new Slave Address for this module (1..127) ?");
if(scanf("%d",&new_Address)!=1)
printf("Invalid value! configuration not change.\n");
else
{
if(new_Address>0)
if(new_Address<128)
{
if(IsModuleFound(mb,new_Address))
{
modbus_set_slave(mb,CurrentSlaveAddress);
printf("Address already used!\nConfiguration not changes.\n");
}
else
{
modbus_set_slave(mb,CurrentSlaveAddress);
// unlock confiration
modbus_write_register(mb,0x1ff,0x5678);
modbus_write_register(mb,160,new_Address);
printf("Module is now on Address %d\n",new_Address);
CurrentSlaveAddress=new_Address;
}
}
else
printf("Invalid value! configuration not change.\n");
}
usleep(1000000); // delay needed to store data into eerom
IsModuleFound(mb,CurrentSlaveAddress);
}
unsigned short getConfigMode(modbus_t * mb, int Pin)
{
uint16_t MB_Register;
if( modbus_read_registers(mb,0x100+Pin,1,&MB_Register) < 0)
return 65535;
return MB_Register;
}
int IsModuleFound(modbus_t * mb, unsigned char SlaveAddress)
{
int rcode;
uint16_t MB_Register;
if(SlaveAddress >127) return 0;
modbus_set_slave(mb,SlaveAddress);
if (modbus_read_registers(mb,251,1,&MB_Register) <0)
return 0;
if (modbus_read_registers(mb,250,1,&MB_Version) <0)
MB_Version=0;
if(MB_Register == 0x6532)
return 0x6532;
if(MB_Register == 0x653A)
return 0x653A;
return 0;
}
unsigned char selectModule(modbus_t * mb)
{
char buffer[256];
int SlaveAddress;
int rcode;
uint16_t MB_Register;
CurrentSlaveAddress=255;
CurrentSlaveIOCount=0;
CurrentSlaveId=0;
printf("Select Module\nEnter Slave Address ?");
if(scanf("%d",&SlaveAddress)==1)
if(SlaveAddress>0)
if(SlaveAddress<128)
{
CurrentSlaveId=IsModuleFound(mb,SlaveAddress);
CurrentSlaveIOCount = CurrentSlaveId & 0xf;
CurrentSlaveAddress=SlaveAddress;
}
printf("\n");fflush(stdout);
return SlaveAddress;
}
void changeConfigMode(modbus_t * mb,int Pin)
{
int loop;
unsigned short mode;
unsigned char module;
int new_mode;
uint16_t MB_mode;
printf("\n======= Change IO%d mode\n",Pin);
if(CurrentSlaveAddress == 255)
selectModule(mb);
else
if(!IsModuleFound(mb,CurrentSlaveAddress))
selectModule(mb);
if(CurrentSlaveAddress==255) return;
mode=getConfigMode(mb,Pin);
for(loop=0;;loop++)
{
if(configInfo[loop].mode==65535) break;
if(loop%3==0)
printf("\n");
if(IsConfigValidOnPin(configInfo[loop].mode,Pin))
printf("%3d) %-20s",configInfo[loop].mode, configInfo[loop].asciiMode);
else
printf("%3s %-20s"," "," ");
fflush(stdout);
}
printf("\n\nSlave address %d current IO%d mode is %d : %-20s\n",CurrentSlaveAddress,Pin,mode,configModeInText(mode));
printf("\nEnter new configuration ?");
if(scanf("%d",&new_mode)!=1)
printf("Invalid value! configuration not change.\n");
else
{
if(IsConfigValidOnPin(new_mode,Pin))
{
MB_mode= new_mode;
// Enable configuration change
modbus_write_register(mb,0x1ff,0x5678);
modbus_write_register(mb,0x100+Pin,MB_mode);
printf("Module %d IO%d set to %d: %s\n",CurrentSlaveAddress,Pin,MB_mode,configModeInText(MB_mode));
}
else
printf("Invalid value! configuration not change.\n");
}
usleep(1000000); // delay needed to store data into eerom
}
void ReadDS18B20(modbus_t * mb,int _io)
{
float Factor=0.0625,Temperature;
int mask;
short Temp;
uint16_t MB_Register[3];
if(modbus_read_input_registers(mb,_io*16,3,MB_Register)>=0)
{
if(MB_Register[0]==0)
{
printf("Buzy");
}
else if (MB_Register[0]==1)
{
mask = MB_Register[2] & 0x60;
Temperature = Factor * ((short)MB_Register[1]);
printf("Temp: %5.1f Celsius",Temperature);
}
else if (MB_Register[0]==2)
{
printf("CRC Error");
}
else printf("Error");
}
else
printf("Unable to read Sensor");
printf("\n");
}
void ServoData(modbus_t * mb, unsigned char _io)
{
uint16_t MB_Register;
int loop;
if(modbus_read_registers(mb,_io,1,&MB_Register)<0)
printf("Unable to read data\n");
else
{
printf("[%d (0x%04X)] ",MB_Register,MB_Register);
printf("\n");
}
}
void RawData(modbus_t * mb, unsigned char _io, unsigned char Size)
{
uint16_t MB_Register[3];
int loop;
if(modbus_read_input_registers(mb,_io*16,Size,MB_Register)<0)
printf("Unable to read data\n");
else
{
for(loop=0;loop<Size;loop++)
printf("[%d (0x%04X)] ",MB_Register[loop],MB_Register[loop]);
printf("\n");
}
}
void ReadDHT22(modbus_t * mb,int _io)
{
float Factor,Temperature,Humidity;
static char status[256];
uint16_t MB_Register[3];
// printf("%-20s","DHT22");
if(modbus_read_input_registers(mb,_io*16,3,MB_Register)>=0)
{
if(MB_Register[0]==0)
{
printf("Buzy");
}
else if (MB_Register[0]==1)
{
if(MB_Register[2] & 0x8000)
Factor = (-0.1);
else
Factor = (0.1);
Temperature = (MB_Register[2] & 0x7fff) * Factor;
Humidity = (MB_Register[1] * 0.1);
printf("Temp: %5.1f Celsius Humidity: %5.1f%%",
Temperature,Humidity);
}
else printf("Error");
}
else
printf("Unable to read DHT22 Sensor");
printf("\n");
}
void ReadDHT11(modbus_t * mb,int _io)
{
float Temperature,Humidity;
static char status[256];
uint16_t MB_Register[3];
if(modbus_read_input_registers(mb,_io*16,3,MB_Register)>=0)
{
if(MB_Register[0]==0)
{
printf("Buzy");
}
else if (MB_Register[0]==1)
{
Temperature = (MB_Register[2] & 0xff);
Humidity = (MB_Register[1] &0xff);
printf("Temp: %5.0f Celsius Humidity: %5.0f%%",
Temperature,Humidity);
}
else printf("Error");
}
else
printf("Unable to read DHT11 Sensor");
printf("\n");
}
void displaySensorData(modbus_t * mb, int _io)
{
uint16_t IOConfig;
// read io configuration
if(modbus_read_registers(mb,0x100+_io,1,&IOConfig)<0)
{
printf(" Unable to read configuration\n");
return;
}
switch(IOConfig)
{
case IOCONFIG_ANALOGVDD: RawData(mb,_io,1);break;
case IOCONFIG_ANALOG1V: RawData(mb,_io,1);break;
case IOCONFIG_ANALOG2V: RawData(mb,_io,1);break;
case IOCONFIG_ANALOG4V: RawData(mb,_io,1);break;
case IOCONFIG_INPUT:
case IOCONFIG_INPUT_PULLUP:
case IOCONFIG_OUTPUT: RawData(mb,_io,1);break;
case IOCONFIG_CAP_SENSE_OFF:
case IOCONFIG_CAP_SENSE_LOW:
case IOCONFIG_CAP_SENSE_MEDIUM:
case IOCONFIG_CAP_SENSE_HIGH: RawData(mb,_io,2);break;
case IOCONFIG_DHT11: ReadDHT11(mb,_io);break;
case IOCONFIG_DHT22: ReadDHT22(mb,_io);break;
case IOCONFIG_DS18B20: ReadDS18B20(mb,_io);break;
case IOCONFIG_SERVO:
case IOCONFIG_PWM: ServoData(mb,_io);break;
case IOCONFIG_COUNTER_PULLUP:
case IOCONFIG_COUNTER: RawData(mb,_io,3);break;
default: printf("\n");
}
}
void DisplayIOConfig(modbus_t * mb)
{
int loop,io;
int rcode;
uint16_t MB_Register;
int configMode;
double VDD;
if(CurrentSlaveAddress==255)
return;
moduleID = IsModuleFound(mb,CurrentSlaveAddress);
if(moduleID)
{
printf("=============\n%d : ",CurrentSlaveAddress);
printf("Type %04X Multi Purpose %dIO", moduleID, moduleID & 0xf);
printf(" , Version:%d.%02d\n",MB_Version >>8, MB_Version & 0xff);
for(io=0;io<(moduleID & 0xf);io++)
{
printf("%5sIO%d: ","",io);
configMode= getConfigMode(mb,io);
printf("%-20s",configModeInText(configMode));
// check if config is valid
if(IsConfigValidOnPin(configMode,io))
displaySensorData(mb,io);
else
printf("*** INVALID CONFIGURATION ***\n");
}
if(moduleID == 0x653A)
{
uint16_t MB_Register[3];
printf("\n");
// get VDD
if(modbus_read_input_registers(mb,0x1000,1,MB_Register)>=0)
{
if(MB_Register[0]>0)
{
VDD = 2.048 * 1023 / MB_Register[0];
printf("%5sVDD: %5.2fV","",VDD);
// get DIODE A/D
if(modbus_read_input_registers(mb,0x1001,1,MB_Register)>=0)
{
printf(" Diode A/D: %d\n",MB_Register[0]);
}
}
}
}
printf("\n");
}
}
void scanBus(modbus_t * mb)
{
int loop,io;
int rcode;
int Id;
uint16_t MB_Register;
printf("\n==== Scanning MODBUS\n");fflush(stdout);
for(loop=1;loop<128;loop++)
{
Id = IsModuleFound(mb,loop);
if(Id)
{
printf("%d : ",loop);
printf("Type %04X Multi Purpose %dIO\n", Id, Id & 0xf);
/*
Id &= 0xf;
for(io=0;io<Id;io++)
{
printf("IO%d: ",io);
printf("%-20s",configModeInText(getConfigMode(mb,io)));
}
printf("\n");
*/ }
}
}
unsigned char ReadOneKey(void)
{
char c;
struct termios term,term_orig;
// put keyboard in raw mode
tcgetattr(0,&term_orig);
memcpy(&term,&term_orig,sizeof(struct termios));
term.c_lflag &= ~(ICANON | ECHO);
term.c_cc[VTIME] =0;
term.c_cc[VMIN]=1;
tcsetattr(0,TCSANOW, &term);
while(read(0, &c,1)!=1);
tcsetattr(0,TCSANOW,&term_orig);
fflush(stdin);
return c;
}
void ResetModule(modbus_t * mb)
{
char rcode;
char loop;
printf("Reset Module (Y/N)?");fflush(stdout);
rcode = toupper(ReadOneKey());
if(rcode!='Y') return;
modbus_write_register(mb,0xAA55,0x1234);
printf("\n***** Resetting module ****\nPlease wait");fflush(stdout);
for(loop=0;loop<10;loop++)
{
usleep(500000);
printf(".");fflush(stdout);
}
printf("\n");
modbus_flush(mb);
}
void SetOutputSignal(modbus_t * mb)
{
char rcode;
int SelectedIO;
uint16_t MB_Register;
int value;
printf("**** works for Output , PWM and R/C Servos only\n");
printf("Select IO (0..9)?");fflush(stdout);
rcode = toupper(ReadOneKey());
if(rcode < '0') return;
if(rcode > '9') return;
SelectedIO = rcode - '0';
printf("\nEnter Data signal ?");fflush(stdout);
if(scanf("%d",&value)==1)
{
MB_Register=value;
modbus_write_register(mb,SelectedIO,MB_Register);
}
printf("\n");
}
void Menu(modbus_t * mb)
{
char rcode;
int SelectedIO;
printf("\nPIC multi-purpose I/O MODBUS configuration\n");
printf("Version 1.0 (c) Daniel Perron, April 2014\n");
printf("device:%s Baud Rate:%d timeout:%uus\n",device,Baud,timeout);
while(1)
{
// print menu
printf("\n\nM) MODBUS scan \n");
printf("F) FLush buffer\n");
printf("A) Select Slave Module\n");
if(CurrentSlaveAddress!=255)
{
printf("I) DispLay IO configuration\n");
printf("S) Set Output signal\n");
printf("R) Reset Module\n");
}
printf("C) Change Slave Address\n");
printf("0..9) Set IO mode\n");
printf("Q) Quit\n");
printf("\nSelected module :");
if(CurrentSlaveAddress == 255)
printf("None\n");
else
printf("%d\n",CurrentSlaveAddress);
fflush(stdout);
rcode= toupper(ReadOneKey());
fflush(stdin);
switch(rcode)
{
case 'M': scanBus(mb);break;
case 'F': modbus_flush(mb);
printf("Flush Received data....");
fflush(stdout);
usleep(500000);
break;
case 'I': if(CurrentSlaveAddress!=255)
DisplayIOConfig(mb);
break;
case 'A': selectModule(mb);break;
case 'C': changeAddress(mb);break;
case 'S': if(CurrentSlaveAddress != 255)
SetOutputSignal(mb);
break;
case 'R': if(CurrentSlaveAddress != 255)
ResetModule(mb);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
SelectedIO= rcode -'0';
if(CurrentSlaveIOCount < SelectedIO)
return;
changeConfigMode(mb,SelectedIO);
break;
case 'Q': return;
}
}
}
int main(int argc, char * argv[])
{
modbus_t *mb;
strcpy(device,DEFAULT_DEVICE);
decodeArg(argc,argv);
timeout = ((timeout + 500) / 1000) * 1000;
if(timeout ==0)
timeout=10000;
if(timeout > 999900)
timeout=999900;
mb = modbus_new_rtu(device,Baud,'N',8,1);
modbus_connect(mb);
//set 1/100th of second response time
// struct timeval response;
// new version used directly uint32_t variable
// response.tv_sec=0;
// response.tv_usec=timeout;
// modbus_set_response_timeout(mb, &response);
modbus_set_response_timeout(mb,0, (uint32_t) timeout);
if(scanOnly==1)
scanBus(mb);
else
Menu(mb);
modbus_close(mb);
modbus_free(mb);
return 0;
}