⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 daxianutil.h

📁 一个通过串口连接手机发短信的程序。
💻 H
字号:
////////////////////////////////////////////////////////////////
//file name : daxianutil.h
//author: weirenhui 
//date:  20040701
//Copyright (2004)
////////////////////////////////////////////////////////////////////
#ifndef _DAXIANUTIL_H_
#define _DAXIANUTIL_H_
#include "stdafx.h"
#include "windows.h"
//////////////////////////////////////////////////////////////
//															//
//			import functions								//
//															//
//////////////////////////////////////////////////////////////
BYTE GetCheckSum(BYTE *buffer);
BOOL SetCheckSum(BYTE *buffer, BYTE checkSum);
void DelayMilinSecond(DWORD second);
BOOL FillDCB(HANDLE hComm,DWORD baudRate);
DWORD ReadComPort(HANDLE hComm,unsigned char *data, const DWORD dwBlockSize);
DWORD WriteToComPort(HANDLE hComm,const unsigned char *data, const DWORD dwBlockSize);
BOOL SetComTimeOut(HANDLE hComm,DWORD timeRead);
////////////////////////////////////////////////////////////////////////////////
//Text : text to be convert
// typeIn: the input type of text 0 hex 1 dec 2 oct 3 bin
//typeOut: type of output to value
//			0-unsigned char
//			1-signed char			
//			0-unsigned short
//			1-signed short			
//			0-unsigned int
//			1-signed int			
//value :  the out put value array
int TextToValue(char* Text,int typeIn,int typeOut,void* value);

////////////////////////////////////////////////////////////////////////////////
//							String operation								  //
//																			  //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
//function name DxApi_GetSubString
// str: source string
// index:the index of substing
// split:the split to substring
// sub: the store of substing
//return 
//	TRUE sucssess
//	FALSE no sub string got
BOOL DxApi_GetSubString(char* str,int index,char split,char* sub);//get substring
//function StringToValue
// str:source string
//len :len of value elements
// split :split of string
//typeValue: value type
//TextType:type of store in string such as Hex or Dec etc.
//value:output store
//return : 0 success -1 error

int	 DxApi_StringToValue(char* str,int len,char split,int typeValue,char textType,void* value);
////////////////////////////////////////////////////////////////////////////////////////////
//function ValueToString
// value:source value
//typeIn:type of value element
//len :len of value elements
//TextType:type of store in string such as Hex or Dec etc.
// split :split of string
//str:output store

int	 DxApi_ValueToString(void* value,int typeIn,int len,int typeText ,char split,char* str);
////////////////////////////////////////////////////////////////////////////////
//function name DxApi_SendPortBuffer
//hComm :handle of comm port to be send
//len   :length of data to be send
//buffer:buffer entry to be send
//return:
//		 success: 0
//		 error: -1
//		 timeout  -2
//description 
//		 send buffer to comm port
int     DxApi_SendPortBuffer(HANDLE hComm,int len,BYTE* buffer);
////////////////////////////////////////////////////////////////////////////////
//function name DxApi_ReceivePortBuffer
//hComm :handle of comm port that received from
//buffer:buffer entry to store the receiving data
//return:
//		 success: bytes of receiving data
//		 error: -1
//		 timeout  -2 or no respone
//description
//		 receive a buffer from comm port
int     DxApi_ReceivePortBuffer(HANDLE hComm,BYTE* buffer);
////////////////////////////////////////////////////////////////////////////////
//function name DxApi_ListenPortByte
//hComm :comm port handle to be listen
//return:
//		0x02 start
//		0x06 ACK
//		0x15 NAK
//description
//		listen a byte from comm port
BYTE     DxApi_ListenPortByte(HANDLE hComm);
////////////////////////////////////////////////////////////////////////////////
//function name DxApi_SendPortByte
//hComm :comm port handle to be send
//byte	:
//		ACK: 0x06
//		NAK: 0x15
//return:
//		success 0
//		error : -1
//		timeout :-2
//description
//		send a byte to comm port
int     DxApi_SendPortByte(HANDLE hComm,BYTE byte);


////////////////////////////////////////////////////////////////////////////////////
//							Packing operation									  //
//																			      //
////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
//function name DxApi_GetPacks
//len : the length of signal to be packed
//type: the type of signal to be packed
//buffer: the buffer to be packet
//index: index of sub packets
//outPacket; sub packet
//return:
//		success 0
//		error : -1
//input: TYPE| LEN | DATA
//output: MSGID |LAST/ONLY |DATA|
//description
//		get the sub packets from the input buffer 
int DxApi_GetPacks(int len,BYTE type,BYTE* buffer,int index, BYTE* outPacket);
////////////////////////////////////////////////////////////////////////////////
//function name DxApi_CatPacks
//outPacket: the packet output after cat
//lenOut:	the initialize length of outPacket
//subPacket: the sub packet to be cat to outpacket
//lenSub :the lenght of sub packet
//type: the type of receive signal
//return :
//		  length of outPacket
//		  -1 packet error
int DxApi_CatPacks(BYTE* outPacket,int lenOut,BYTE* subPacket,int lenSub,BYTE& type);
////////////////////////////////////////////////////////////////////////////////
//function name DxApi_IsLastPacks
//packet: the check packet
//return TRUE last packet
//       FALSE not last packet		 
BOOL DxApi_IsLastPacks(BYTE* Packet);

////////////////////////////////////////////////////////////////////////////////////
//							Command parsers  									  //
//																			      //
////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
//function name DxApi_MakeSendSignal
//signal: signal ID
//srcTask: source task ID
//dstTask: destination task ID
//len:		length of data
//inData:	the data contents
//outData:  the output buffer
//return 0: success
//		 -1 error
int DxApi_MakeSendSignal(WORD singal,WORD srcTask,WORD dstTask,int len,BYTE* inData,BYTE* outData);
////////////////////////////////////////////////////////////////////////////////////
//function name DxApi_MakeSendCmd
//cmdType	type of command
//len:		length of data
//inData:	the data contents
//outData:  the output buffer
//return 0: success
//		 -1 error
int DxApi_MakeSendCmd(BYTE cmdType,int len,BYTE* inData,BYTE* outData);
////////////////////////////////////////////////////////////////////////////////////
//function name DxApi_GetReceiveData
//len	length of data to be get
//type	there is two type 0xD4 and 0xD3
//return 
//		success: signal id
//		-1 error
//input Len|Data
//output | data contents
int DxApi_GetReceiveData(int len,int type,BYTE* receiveData,int* lenOut,BYTE* outData);
////////////////////////////////////////////////////////////////////////////////////
//
//								Terminal User Interface API
//
/////////////////////////////////////////////////////////////////////////////////////

//function name: DxApiSendSignal
//hComm :handle of comm port
//timeout:send timeout
//cmdType:	command type
//Cmdbody: command body
//return: 0 success
//		-1 error
// 		-2 timeout
int  DxApi_SendCommand(HANDLE hComm,DWORD timeout,BYTE cmdType,BYTE* bodys);

/////////////////////////////////////////////////////////////////////////////////////
//function name: DxApiSendSignal
//hComm :handle of comm port
//timeout:send timeout
// signalId:	the signal ID to be send
// lenOfSignal: len of signalContents
//signalContens: signal contents
//return: 0 success
//		-1 error
// 		-2 timeout
int DxApi_SendSignal(HANDLE hComm,int timeout,WORD dstTask,WORD signalID,WORD lenSignalContent,BYTE* signalContents);

/////////////////////////////////////////////////////////////////////////////////////
//function name: DxApiReceiveSignal
//hComm: handle of comm port
//timeout: send time out
// signalId:	the signal ID to be send
// lenOfSignal: len of signalContents
//signalContens: signal contents
//return: 0 success
//		-1 error
//		-2 timeout
int DxApi_ReceiveSignal(HANDLE hComm,int timeout,WORD signalID,int *lenSignalContent,BYTE* signalContents);





#endif//_DAXIANUTIL_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -