Skip to content
Browse files

Update Commit

- proper control lines access for both linux & win32 (NOT TESTED!)
- released as 1.3.4 ...
  • Loading branch information...
1 parent b5d1c7c commit ec28be687cf70f7ab0e264c55ee87a42fdee2775 @azman committed Nov 13, 2012
Showing with 79 additions and 44 deletions.
  1. +3 −3 CHANGELOG
  2. +3 −0 TODO
  3. +1 −1 VERSION
  4. +71 −36 src/my1comlib.c
  5. +1 −4 src/my1comlib.h
View
6 CHANGELOG
@@ -1,14 +1,14 @@
**************
-my1termu-1.x.x
+my1termu-1.3.4
**************
Update:
- my1termu no longer has --fast option, all single dash options also removed
-- my1comlib now provides access for control lines DTR/DSR/RTS/CTS (linux-only)
+- my1comlib now provides access for control lines DTR/DSR/RTS/CTS
- my1comport module is deprecated (redundant), but not removed for now
Bugfix:
-- get_keypress inserts escape char into all escaped keypress ('C'!=F9)
+- (win32) get_keypress inserts escape char into all escaped keypress ('C'!=F9)
**************
my1termu-1.3.3
View
3 TODO
@@ -1,3 +1,6 @@
+2012113
+- add DTR/RTS/DSR/CTS utility in my1termu
+
20111006
- define ALL keystrokes
- detect SHIFT/CTRL/ALT/CAPS/NUM keys as well?
View
2 VERSION
@@ -1 +1 @@
-1.3.3
+1.3.4
View
107 src/my1comlib.c
@@ -87,22 +87,24 @@ int open_serial(ASerialPort_t* aPort)
if(aPort->mHandle==INVALID_HANDLE_VALUE)
return 0;
#ifdef DO_MINGW
- /* save configurable params */
- aPort->mDCBsave.BaudRate = aPort->mDCB.BaudRate;
- aPort->mDCBsave.ByteSize = aPort->mDCB.ByteSize;
- aPort->mDCBsave.Parity = aPort->mDCB.Parity;
- aPort->mDCBsave.StopBits = aPort->mDCB.StopBits;
- if(!GetCommState(aPort->mHandle,&aPort->mDCB))
+ /* save current attributes */
+ if(!GetCommState(aPort->mHandle,&aPort->mDCBsave))
{
CloseHandle(aPort->mHandle);
aPort->mHandle = INVALID_HANDLE_VALUE;
return 0;
}
- /* re-assign configurable params */
- aPort->mDCB.BaudRate = aPort->mDCBsave.BaudRate;
- aPort->mDCB.ByteSize = aPort->mDCBsave.ByteSize;
- aPort->mDCB.Parity = aPort->mDCBsave.Parity;
- aPort->mDCB.StopBits = aPort->mDCBsave.StopBits;
+ {
+ /* transfer current to our DCB, needs a swapbuff */
+ DCB cDCB = aPort->mDCB;
+ aPort->mDCB = aPort->mDCBsave;
+ /* re-assign configurable params */
+ aPort->mDCB.BaudRate = cDCB.BaudRate;
+ aPort->mDCB.ByteSize = cDCB.ByteSize;
+ aPort->mDCB.Parity = cDCB.Parity;
+ aPort->mDCB.StopBits = cDCB.StopBits;
+ }
+ /* set desired attributes */
if(!SetCommState(aPort->mHandle,&aPort->mDCB))
{
CloseHandle(aPort->mHandle);
@@ -135,6 +137,8 @@ int close_serial(ASerialPort_t* aPort)
if(aPort->mHandle==INVALID_HANDLE_VALUE)
return cCheck;
#ifdef DO_MINGW
+ /* set saved original attributes */
+ SetCommState(aPort->mHandle,&aPort->mDCBsave);
cCheck = CloseHandle(aPort->mHandle); /* returns !0:success, 0:error! */
#else
/* set saved original attributes */
@@ -543,41 +547,72 @@ int check_incoming(ASerialPort_t* aPort)
#endif
}
/*----------------------------------------------------------------------------*/
-int get_pincode(int mycode)
-{
- int realcode = 0;
- switch(mycode)
- {
- case MY1PIN_DTR: realcode = TIOCM_DTR; break;
- case MY1PIN_DSR: realcode = TIOCM_DSR; break;
- case MY1PIN_RTS: realcode = TIOCM_RTS; break;
- case MY1PIN_CTS: realcode = TIOCM_CTS; break;
- }
- return realcode;
-}
-/*----------------------------------------------------------------------------*/
int assert_pin(ASerialPort_t* aPort, int pin, int assert)
{
+ int status = 0;
#ifdef DO_MINGW
- return 0;
+ switch(pin)
+ {
+ case MY1PIN_DTR:
+ {
+ aPort->mDCB.fDtrControl = assert ?
+ DTR_CONTROL_ENABLE : DTR_CONTROL_DISABLE;
+ break;
+ }
+ case MY1PIN_RTS:
+ {
+ aPort->mDCB.fRtsControl = assert ?
+ RTS_CONTROL_ENABLE : RTS_CONTROL_DISABLE;
+ break;
+ }
+ }
+ if(status)
+ {
+ status = SetCommState(aPort->mHandle,&aPort->mDCB) ? 0 : 1;
+ }
#else
- int status = get_pincode(pin);
- if(assert) status = ioctl(aPort->mHandle, TIOCMBIC, &status);
- else status = ioctl(aPort->mHandle, TIOCMBIS, &status);
- return status;
+ switch(pin)
+ {
+ case MY1PIN_DTR: status = TIOCM_DTR; break;
+ case MY1PIN_RTS: status = TIOCM_RTS; break;
+ }
+ if(status)
+ {
+ assert = assert ? TIOCMBIC : TIOCMBIS;
+ status = ioctl(aPort->mHandle, assert, &status);
+ }
#endif
+ return status;
}
/*----------------------------------------------------------------------------*/
-int toggle_pin(ASerialPort_t* aPort, int pin)
+int detect_pin(ASerialPort_t* aPort, int pin, int *detect)
{
+ int status = 0;
#ifdef DO_MINGW
- return 0;
+ switch(pin)
+ {
+ case MY1PIN_DSR: status = MS_DSR_ON; break;
+ case MY1PIN_CTS: status = MS_CTS_ON; break;
+ }
+ if(status)
+ {
+ DWORD check;
+ *detect = status;
+ status = GetCommModemStatus(aPort->mHandle,&check) ? 0 : 1;
+ if(!status) *detect &= check;
+ }
#else
- int status = get_pincode(pin);
- ioctl(aPort->mHandle, TIOCMGET, &status);
- status ^= pin;
- ioctl(aPort->mHandle, TIOCMSET, &status);
- return status&pin;
+ switch(pin)
+ {
+ case MY1PIN_DSR: status = TIOCM_DSR; break;
+ case MY1PIN_CTS: status = TIOCM_CTS; break;
+ }
+ if(status)
+ {
+ *detect = status;
+ status = ioctl(aPort->mHandle, TIOCMGET, detect);
+ }
#endif
+ return status;
}
/*----------------------------------------------------------------------------*/
View
5 src/my1comlib.h
@@ -25,13 +25,10 @@
#define MY1BAUD460800 6
#define MY1BAUD921600 7
/*----------------------------------------------------------------------------*/
-#ifdef DO_MINGW
-#else
#define MY1PIN_RTS 0
#define MY1PIN_CTS 1
#define MY1PIN_DTR 2
#define MY1PIN_DSR 3
-#endif
/*----------------------------------------------------------------------------*/
typedef unsigned char byte_t;
/*----------------------------------------------------------------------------*/
@@ -79,7 +76,7 @@ int check_incoming(ASerialPort_t* aPort);
/** e.g. assert_pin(&cPort,MY1PIN_DTR,1); */
/** Note: assert is CLEAR BIT but gets a HIGH at pin! */
int assert_pin(ASerialPort_t* aPort, int pin, int assert);
-int toggle_pin(ASerialPort_t* aPort, int pin);
+int detect_pin(ASerialPort_t* aPort, int pin, int *detect);
/*----------------------------------------------------------------------------*/
#endif
/*----------------------------------------------------------------------------*/

0 comments on commit ec28be6

Please sign in to comment.
Something went wrong with that request. Please try again.