Код: Выделить всё
int m_nSendType; // Send type
IntPtr m_pSendParams; // Params
public FormSDK()
{
InitializeComponent();
// init send type and send params
bool bSendUseIp = true;
// IP
if (bSendUseIp)
{
m_nSendType = 0;
string strParams = "192.168.2.201";
m_pSendParams = Marshal.StringToHGlobalUni(strParams);
}
else
{
// Serial port see Cmd_GetBaudRate Cmd_SetBaudRate
int nSerialPort = 4;
int nBaudRate = 57600;
string strParams = nSerialPort.ToString() + ":" + nBaudRate.ToString();
m_nSendType = 1;
m_pSendParams = Marshal.StringToHGlobalUni(strParams);
}
}
~FormSDK()
{
Marshal.FreeHGlobal(m_pSendParams);
}
// Text
private void buttonText_Click(object sender, EventArgs e)
{
IntPtr pNULL = new IntPtr(0);
int nErrorCode = -1;
// 1. Create a screen
int nWidth = 64;
int nHeight = 32;
int nColor = 1;
int nGray = 1;
int nCardType = 0;
int nRe = CSDKExport.Hd_CreateScreen(nWidth, nHeight, nColor, nGray, nCardType, pNULL, 0);
if (nRe != 0)
{
nErrorCode = CSDKExport.Hd_GetSDKLastError();
return;
}
// 2. Add program to screen
int nProgramID = CSDKExport.Hd_AddProgram(pNULL, 0, 0, pNULL, 0);
if (nProgramID == -1)
{
nErrorCode = CSDKExport.Hd_GetSDKLastError();
return;
}
int nX = 0;
int nY = 0;
int nAreaWidth = 64;
int nAreaHeight = 32;
// 3. Add Area to program
int nAreaID = CSDKExport.Hd_AddArea(nProgramID, nX, nY, nAreaWidth, nAreaHeight, pNULL, 0, 0, pNULL, 0);
if (nAreaID == -1)
{
nErrorCode = CSDKExport.Hd_GetSDKLastError();
return;
}
// 4.Add text AreaItem to Area
IntPtr pText = Marshal.StringToHGlobalUni("12345");
IntPtr pFontName = Marshal.StringToHGlobalUni("Arial");
int nTextColor = CSDKExport.Hd_GetColor(255, 0, 0);
int nAreaItemID = CSDKExport.Hd_AddSimpleTextAreaItem(nAreaID, pText, nTextColor, 0, 4, pFontName, 16, 0, 30, 201, 3, pNULL, 0);
if (nAreaItemID == -1)
{
Marshal.FreeHGlobal(pText);
Marshal.FreeHGlobal(pFontName);
nErrorCode = CSDKExport.Hd_GetSDKLastError();
return;
}
Marshal.FreeHGlobal(pText);
Marshal.FreeHGlobal(pFontName);
// 5. Send to device
nRe = CSDKExport.Hd_SendScreen(m_nSendType, m_pSendParams, pNULL, pNULL, 0);
if (nRe != 0)
{
nErrorCode = CSDKExport.Hd_GetSDKLastError();
}
}
Нужны ли какие-либо дополнительные настройки, помимо кода, который они предоставляют в демо-версии, для решения этой проблемы?
Подробнее здесь: https://stackoverflow.com/questions/771 ... controller