Introduction, NkComPort_Close, NkComPort_GetConnectionDetails, NkComPort_IsConnected, NkComPort_ListPorts, NkComPort_Open, NkComPort_Read, NkComPort_ReadLine, NkComPort_SelectPortDialog, NkComPort_Write, NkComPort_WriteLine
Description
Introduction();
Import (“NkComPort.dll”);
The functions in the NkComPort.dll library implement sending and receiving data through a COM port connection. Run the macro ~nis\macros\NkComPort.mac to load the library in NIS. The example macro: ~nis\Examples\NkComPortDemo.mac illustrates the use of the commands. The example macro includes an Arduino sketch that can be used for the proof-of-principle test.
Example:
# fragment from ~nis\Examples\NkComPortDemo.mac: ... result = NkComPort_Open(&NCPD_port,buf); if(result < 0) { NCPD_Error(result); return 0; } NCPD_Log("port opened.",""); while(NCPD_ReadLine()) {} ...
Description
NkComPort_Open( int64port_handle
, char *port_and_protocol
);
Opens the specified port. The function returns 1 on success, another value on failure. The port_and_protocol string specifies the port name, optionally followed by the communication details. If the communication details are not present, the default values are used as set in the Windows Device Manager Properties Port Settings dialog.
Parameters
Description
NkComPort_IsConnected(
int64 port_handle
);
Returns if the port is successfully opened. The function returns 1 when connected, 0 otherwise.
Description
NkComPort_GetConnectionDetails( int64port_handle
, char *Buffer
, longcount
);
Fills the buffer with the name and communication details of the current connection.
Description
NkComPort_Close(
int64 port_handle
);
Closes the port. The port_handle variable is set to 0.
Description
NkComPort_Read( int64port_handle
, char *Buffer
, longcount
);
Reads the specified number of characters from the port. The function returns as soon as the specified number of characters were received or when the timeout period expires. It returns the number of characters read, -1 in case of an error. The received ASCII characters are converted to the UNICODE characters NIS uses.
Description
NkComPort_ReadLine( int64port_handle
, char *Buffer
, longcount
);
Reads the specified number of characters from the port up to a carriage-return character \r (13). The function returns as soon as the specified number of characters were received, a newline character was received or when the timeout period expires. It returns the number of characters read, -1 in case of an error. The received ASCII characters are converted to the UNICODE characters NIS uses.
Description
NkComPort_Write( int64port_handle
, char *Buffer
, longcount_to_write
);
Writes the specified number of characters to the port. If count is 0, the full string is send. The count or string length must be 1024 or lower. It returns the number of characters written, -1 in case of an error. The UNICODE characters NIS uses are converted and send as ASCII characters to the port.
Description
NkComPort_WriteLine( int64port_handle
, char *Buffer
);
Writes the string to the port. If not present, a trailing carriage-return \r (13) is appended. The length must be 1024 or lower. It returns the number of characters written, -1 in case of an error. The UNICODE characters NIS uses are converted and send as ASCII characters to the port.
Description
NkComPort_ListPorts( int64port_handle
, char *Buffer
, longcount
);
Fills the buffer with the information on the available COM ports. The information on each port has three fields separated by a tab character \t (9) and is terminated by a newline \n (10) character: <name>\t<friendly-name>\t<VID, PID>\n.