- va_list args;
- int len;
-
- va_start(args, Format);
- len = vsnprintf(NULL, 0, Format, args);
- va_end(args);
-
- {
- char buf[len+1];
- va_start(args, Format);
- vsnprintf(buf, len+1, Format, args);
- va_end(args);
-
- #if DEBUG
- printf("Writef: %s", buf);
- #endif
-
- return write(giCoke_SerialFD, buf, len);
- }
-
-}
-
-int WaitForColon()
-{
- fd_set readfs;
- char ch = 0;
-
- FD_SET(giCoke_SerialFD, &readfs);
-
- while( (ch = ReadChar()) != ':' && ch != 0);
-
- if( ch == 0 ) return -1; // Timeout
-
- return 0;
-}
-
-int ReadLine(int len, char *output)
-{
- char ch;
- int i = 0;
-
- for(;;)
- {
- ch = ReadChar();
-
- if( i < len )
- output[i++] = ch;
-
- if( ch == '\0' ) {
- break;
- }
- if( ch == '\n' || ch == '\r' ) {
- if( i < len )
- output[--i] = '\0';
- break;
- }
- }
-
- if( !ch ) return -1;
- return i;
+ errno = 0;
+ if( !gCoke_Modbus && Coke_int_ConnectToPLC() )
+ return -1;
+ if( modbus_write_bit( gCoke_Modbus, BitNum, Value != 0 ) >= 0 )
+ return 0;
+ if( Coke_int_ConnectToPLC() )
+ return -1;
+ if( modbus_write_bit( gCoke_Modbus, BitNum, Value != 0 ) >= 0 )
+ return 0;
+ return -1;