Moderator: Freon
// stopbits = 1
// databits = 8
// parity = 0
// baudrate = 4800
intHandle = CreateFile("COM" + port.ToString() + ":", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if (intHandle != INVALID_HANDLE_VALUE)
{
//----- clear comm port rx and tx buffer
intResult = PurgeComm(intHandle, PURGE_RXCLEAR | PURGE_TXCLEAR);
//----- get existing comm port configuration
intResult = GetCommState(intHandle, out lpDCB);
//----- set required comm port configuration
lpDCB.fBinary = 1; // binary mode, so no EOF check
lpDCB.fParity = 1; // enable parity checking
lpDCB.fOutxCtsFlow = 0; // No CTS output flow control
lpDCB.fOutxDsrFlow = 0; // No DSR output flow control
lpDCB.fDtrControl = 1; // DTR_CONTROL_ENABLE = 1 // DTR flow control type
lpDCB.fDsrSensitivity = 0; // DSR sensitivity
lpDCB.fTXContinueOnXoff = 1; // XOFF continues Tx
lpDCB.fOutX = 0; // No XON/XOFF out flow control
lpDCB.fInX = 0; // No XON/XOFF in flow control
lpDCB.fErrorChar = 0; // Disable error replacement
lpDCB.fNull = 0; // Disable null stripping
lpDCB.fRtsControl = 0; // RTS_CONTROL_ENABLE = 1 // RTS flow control
lpDCB.fAbortOnError = 0; // Do not abort reads/writes on error
lpDCB.StopBits = stopbits; // 0, 1, 2 = 1, 1.5, 2
lpDCB.ByteSize = databits; // Number of bits/byte, 4-8
lpDCB.Parity = parity; // 0-4 = no, odd, even, mark, space
lpDCB.BaudRate = baudrate; // baud rate (port speed)
// XonChar may not equal XoffChar to prevent SetCommState from failing.
// I picked a random character. Perhaps this should be something else.
lpDCB.XoffChar = (char)0x32;
lpDCB.XoffChar = (char)0x33;
lpDCB.XonLim = 2048;
lpDCB.XoffLim = 512;
intResult = SetCommState(intHandle, ref lpDCB);
//----- set comm port buffer size in number of bytes
intResult = SetupComm(intHandle, rxbuffersize, txbuffersize);
//----- set comm port timeouts mintTimeout miliseconds
lpCommTimeouts.ReadIntervalTimeout = 500;
lpCommTimeouts.ReadTotalTimeoutMultiplier = 0;
lpCommTimeouts.ReadTotalTimeoutconstant = timeout;
lpCommTimeouts.WriteTotalTimeoutMultiplier = 0;
lpCommTimeouts.WriteTotalTimeoutconstant = 5000;
intResult = SetCommTimeouts(intHandle, lpCommTimeouts);
}
OUT: 0x80 0x10 0xF0 0x1 0xBF 0x40
IN : 0x3F 0xD 0xD 0x3E 0x80 0x10 0xF0 0x1 0xBF 0x40 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
OUT: 0x80 0x10 0xF0 0x11 0xA8 0x0 0x0 0x0 0x11 0x0 0x0 0xE 0x0 0x0 0xF 0x0 0x0 0x15 0x0 0x0 0x22 0x9E
IN : 0x80 0x10 0xF0 0x11 0xA8 0x0 0x0 0x0 0x11 0x0 0x0 0xE 0x0 0x0 0xF 0x0 0x0 0x15 0x0 0x0 0x22 0x9E 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
OUT: 0x80 0x10 0xF0 0x11 0xA8 0x0 0x0 0x0 0x11 0x0 0x0 0xE 0x0 0x0 0xF 0x0 0x0 0x15 0x0 0x0 0x22 0x9E
IN : 0x80 0x10 0xF0 0x11 0xA8 0x0 0x0 0x0 0x11 0x0 0x0 0xE 0x0 0x0 0xF 0x0 0x0 0x15 0x0 0x0 0x22 0x9E 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
OUT: 0x80 0x10 0xF0 0x11 0xA8 0x0 0x0 0x0 0x11 0x0 0x0 0xE 0x0 0x0 0xF 0x0 0x0 0x15 0x0 0x0 0x22 0x9E
IN : 0x80 0x10 0xF0 0x11 0xA8 0x0 0x0 0x0 0x11 0x0 0x0 0xE 0x0 0x0 0xF 0x0 0x0 0x15 0x0 0x0 0x22 0x9E 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
OUT: 0x80 0x10 0xF0 0x11 0xA8 0x0 0x0 0x0 0x11 0x0 0x0 0xE 0x0 0x0 0xF 0x0 0x0 0x15 0x0 0x0 0x22 0x9E
IN : 0x80 0x10 0xF0 0x11 0xA8 0x0 0x0 0x0 0x11 0x0 0x0 0xE 0x0 0x0 0xF 0x0 0x0 0x15 0x0 0x0 0x22 0x9E 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
javasti wrote:I don't think he has his source code available, at least I couldn't find it. I'm going to keep messing around with the comms... In the meantime if anyone has any input on the code or datalog above please let me know.
Return to Data Logging Software
Users browsing this forum: No registered users and 1 guest