?»??»?//////////////////////////////////////////////////////////////////////////////////////// // Header file : SoyalComm.h // // Copyright (c), Soyal Technology Co., LTD. TAIWAN // // SoyalComm.DLL : Version 1.01 2004,JUL,08 // SOYAL PROTOCOL multi port driver for WIN32 // // All rights are reserved. Reproduction in whole or in part is prohibited // without the written consent of the copyright owner. // Soyals reserves the right to make changes without notice at any time. // Soyals makes no warranty, expressed, implied or statutory, including but // not limited to any implied warranty of merchantability or fitness for // any particular purpose. // Soyals must not be liable for any loss or damage arising from its use. // //////////////////////////////////////////////////////////////////// // BOOL IsPortAvailable( int CommPort ) // In : Serial port number (0 ... n) for COM:1 ... COM:n+1 // Returns: If the port is available or not // //////////////////////////////////////////////////////////////////// // void* CreateSPort( void ) // // Returns: If create successfully return the pointer of Item object that // represents the communication object that is created. otherwise return NULL // Effect: Use the method to create a objec for communication to a serial device // //////////////////////////////////////////////////////////////////// // BOOL DeleteSPort( void *pComm ) // Returns: Nonzero if successful; otherwise zero // Effect: Delete the object created by CreateSPort() // //////////////////////////////////////////////////////////////////// // BOOL OpenSComm( void *pComm, int Port ) // In : Communication Object address, that create by CreateSPort // Serial port number ( Ex: 0 for port COM1, 1 for port COM2 ) // Returns: Nonzero if the opening was successful // Effect: Connect the communication object to serial port in 9600,N,8,1 // //////////////////////////////////////////////////////////////////// // BOOL CloseSComm( void *pComm ) // In : Communication Object address, that create by CreateSPort // Returns: Nonzero if the opening was successful // Effect: DisConnect the communication object with serial port // //////////////////////////////////////////////////////////////////// // BOOL ReadWriteSComm( void *pComm, BYTE* TxBfx, BYTE* RxBfx, WORD* pLen ) // In : Communication Object address, that create by CreateSPort // TxBfx: Address of data block to transmit // RxBfx: reserved memory block to receive data // SendLength: number of bytes to transmit // Returns: Nonzero if all bytes transmited and put the received bytes in *pLen // Effect: Transmits *pLen bytes of data from TxBfx to the serial port, // and receive the return data in RxBfx // //////////////////////////////////////////////////////////////////// // DWORD GetSCommStatus( void *pComm ) // In : Communication Object address, that create by CreateSPort // Returns: Return unsigned long data of last ReadWriteSComm status // //////////////////////////////////////////////////////////////////// // BOOL ConfigSComm( void *pComm, int baud ) // In : Communication Object address, that create by CreateSPort // Serial port speed // Returns: Nonzero if all bytes transmited and put the received bytes in *pLen // Effect: After OpenSComm the serial port parameters will be 9600,N,8,1 // Use this function can change baud. //////////////////////////////////////////////////////////////////// // BOOL ConfigSCommParity( void *pComm, int baud, int Parity ) // In : Communication Object address, that create by CreateSPort // Serial port speed // Parity: 0: Non Parity 1:Even Parity, 2:Odd Parity // Returns: Nonzero if all bytes transmited and put the received bytes in *pLen // Effect: After OpenSComm the serial port parameters will be 9600,N,8,1 // Use this function can change baud. //////////////////////////////////////////////////////////////////////////// // Usage: // // // #include "SoyalComm.h" // // void main() // { // void* pComm; // int i; // WORD nLen; // BYTE TxBfx[256], RxBfx[256]; // DWORD deError; // // ////////////////////////////////////////////////////// // // Fine the available serial ports from COM1 ... COM6 // for( i=0; i < 6; i++ ) { // if( IsPortAvailable( i ) ) { // // Do something like add to selection box // } // } // // if( (pComm = CreateSPort()) == NULL ) { // printf( "Cann't create SoyalComm object !\n" ); // return; // } // // //////////////////////////////////////////////////////// // // Connect the SoyalComm object to serial port (COM1) // if( OpenSComm( pComm, 0 ) { // // Command of Soyal AR737H1356: // TxBfx[0] = 0xFF; // Destination Node Address // TxBfx[1] = 0x12; // Node information // TxBfx[2] = 0x02; // Read Command // TxBfx[3] = 'R'; // Parameters // nLen = 4; // Get AR721H Node(001) Event -> TxBfx[0] = 0x01, TxBfx[1] = 0x18, nLen = 2 // if( ReadWriteSComm( pComm, TxBfx, RxBfx, &nLen ) ) { // /////////////////////////////////////////////////// // // The Header code will be included in return data // // RxBfx: 7E 0C 01 ... // // Do something // // ... // } else { // dwError = GetSCommStatus( pComm ); // if( dwError & COMM_RXTIMEOUT ) { // printf( "Timeout !\n" ); // } // if( dwError & COMM_RXERRSUM ) { // printf( "Check Sum Error !\n" ); // } // if( dwError & COMM_TXERRLENGTH ) { // printf( "Cann't send to serial port !\n" ); // } // } // CloseSComm( pComm ); // } else { // printf( "Cann't connect to serial port " ); // } // DeleteSPort( pComm ); // return; // // } // ///////////////////////////////////////////////////////////////////////////////////////// // The following ifdef block is the standard way of creating macros which make exporting // from a DLL simpler. All files within this DLL are compiled with the SOYALCOMM_EXPORTS // symbol defined on the command line. this symbol should not be defined on any project // that uses this DLL. This way any other project whose source files include this file // SOYALCOMM_API functions as being imported from a DLL, wheras this DLL sees symbols // see defined with this macro as being exported. #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #ifdef SOYALCOMM_EXPORTS #define SOYALCOMM_API __declspec(dllexport) #else #define SOYALCOMM_API __declspec(dllimport) #endif //////////////////////////////////////////////////////////////////// // Error Conditions and return values. #define COMM_TXOK 0x00000001 #define COMM_RXOK 0x00000002 #define COMM_TXERR 0x00000004 #define COMM_RXERR 0x00000008 #define COMM_RXTIMEOUT 0x00000010 #define COMM_RXHEADER 0x00000020 #define COMM_RXLENGTH 0x00000040 #define COMM_RXERRSUM 0x00000080 #define COMM_RXERRXOR 0x00000100 #define COMM_TXERRLENGTH 0x00000200 #define COMM_FRAMEERROR 0x00000400 ///////////////////////////////////////////////////////////////////// // Function Prototypes SOYALCOMM_API BOOL IsPortAvailable( int CommPort ); SOYALCOMM_API void* CreateSPort( void ); SOYALCOMM_API BOOL DeleteSPort( void *pComm ); SOYALCOMM_API BOOL ReadWriteSComm( void *pComm, BYTE* TxBfx, BYTE* RxBfx, WORD* pLen ); SOYALCOMM_API BOOL OpenSComm( void *pComm, int Port ); SOYALCOMM_API BOOL CloseSComm( void *pComm ); SOYALCOMM_API DWORD GetSCommStatus( void *pComm ); SOYALCOMM_API BOOL ConfigSComm( void *pComm, int baud ); SOYALCOMM_API BOOL SetCommType( void *pComm, BOOL Soyal ); #ifdef __cplusplus } #endif /* __cplusplus */