Commit a607cfb8 by yunpeng.song

增加fec杯贴指令打印

parent 201d7809
#include "stdAfx.h"
#include "ComControl.h"
ComControl::ComControl(void):_comType(0),_hCom(NULL),_portState(0)
{
}
ComControl::~ComControl(void)
{
}
void ComControl::SetComType(int type)
{
_comType = type;
}
void ComControl::SetComSettings(const string& comName, int bandRate, int dataBits, int parity, int stopBits, int param)
{
//comName[] size =96
_comSettings.comName = comName;
_comSettings.bandRate = bandRate;
_comSettings.dataBits = dataBits;
_comSettings.parity = parity;
_comSettings.stopBits = stopBits;
_comSettings.param = param;
}
bool ComControl::OpenCom(string& error)
{
if(0 == _comType)
{
error = string("端口打开失败,请先设置端口类型");
_portState = 0;
return false;
}
DWORD dwError;
_hCom = CreateFile(_comSettings.comName.data(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if ((HANDLE)0xFFFFFFFF == _hCom)
{
dwError = GetLastError();
error.append("端口打开失败,错误类型");
error.append(std::to_string(_ULonglong(dwError)));
_portState = 0;
return false;
}
_portState = 1;
COMMTIMEOUTS TimeOuts;
//设定读超时
TimeOuts.ReadIntervalTimeout = MAXDWORD;
TimeOuts.ReadTotalTimeoutMultiplier = 0;
TimeOuts.ReadTotalTimeoutConstant = 0;
//设定写超时
TimeOuts.WriteTotalTimeoutMultiplier = 100;
TimeOuts.WriteTotalTimeoutConstant = 500;
SetCommTimeouts(_hCom,&TimeOuts); //设置超时
SetupComm(_hCom,1024,1024); //输入缓冲区和输出缓冲区的大小都是1024
//DCB wdcb;
//GetCommState(_hCom, &wdcb);
//wdcb.BaudRate = 9600;//波特率:9600,其他:不变
//wdcb.ByteSize = 8; //每个字节8位
//wdcb.Parity = NOPARITY; //无停止位
//SetCommState(_hCom, &wdcb);
PurgeComm(_hCom,PURGE_TXCLEAR|PURGE_RXCLEAR);
return true;
}
void ComControl::sendCommand(string command)
{
DWORD length = 0;
WriteFile(_hCom,command.data(),command.size(),&length,NULL);
cout<<command.data()<<command.size()<<length;
}
void ComControl::CloseCom()
{
CloseHandle(_hCom);
}
\ No newline at end of file
#pragma once
#define COM 1
#define PARALLEL 2
#define EMAC 3
#define USB 4
#define PORTOPEN 1
#define PORTCLOSE 0
typedef struct{
int bandRate;
int dataBits;
int parity;
int stopBits;
int param;
string comName;
} ComSettings;
class ComControl
{
public:
ComControl(void);
~ComControl(void);
void SetComType(int type);
void SetComSettings(const string& comName, int bandRate, int dataBits, int parity, int stopBits, int param);
bool OpenCom(string& error);
void sendCommand(string command);
void CloseCom();
private:
int _portState;
int _comType;
HANDLE _hCom;
ComSettings _comSettings;
};
#include "stdafx.h"
#include "FECLabPrint.h"
string SetSize(string m, string n)
{
string command;
command.append("SIZE ");
command.append(m);
command.append(" mm,");
command.append(n);
command.append(" mm");
command.append("\r\n");
return command;
}
string SetCashDrawer(double m)
{
string command;
return command;
}
string SetGap(double m, double n)
{
string command;
command.append("GAP ");
command.append(std::to_string(long double(m)));
command.append(" mm,");
command.append(std::to_string(long double(n)));
command.append(" mm");
command.append("\r\n");
return command;
}
string SetOffset(double m)
{
string command;
command.append("OFFSET ");
command.append(std::to_string(long double(m)));
command.append(" mm");
command.append("\r\n");
return command;
}
string SetSpeed(string n)
{
string command;
command.append("SPEED ");
command.append(n);
command.append("\r\n");
return command;
}
string SetDensity(string n)
{
string command;
command.append("DENSITY ");
command.append(n);
command.append("\r\n");
return command;
}
string SetDirection(double n)
{
string command;
command.append("DIRECTION ");
command.append(std::to_string(long long(n)));
command.append("\r\n");
return command;
}
string SetReference(int x, int y)
{
string command;
command.append("REFERENCE ");
command.append(std::to_string(long long(x)));
command.append(",");
command.append(std::to_string(long long(y)));
command.append("\r\n");
return command;
}
string SetShift(int n)
{
string command;
command.append("SHIFT ");
command.append(std::to_string(long long(n)));
command.append("\r\n");
return command;
}
string SetCodePage(int n)
{
string command;
command.append("CODEPAGE ");
command.append(std::to_string(long long(n)));
command.append("\r\n");
return command;
}
string SetCls()
{
string command;
command.append("CLS ");
command.append("\r\n");
return command;
}
string SetFeed(int n)
{
string command;
command.append("FEED ");
command.append(std::to_string(long long(n)));
command.append("\r\n");
return command;
}
string SetBackFeedAndBackup(int n)
{
string command;
command.append("BACKUP ");
command.append(std::to_string(long long(n)));
command.append("\r\n");
return command;
}
string SetFormFeed()
{
string command;
command.append("FORMFEED ");
command.append("\r\n");
return command;
}
string SetHome()
{
string command;
command.append("HOME ");
command.append("\r\n");
return command;
}
string SetSound(int level, int doubleerval)
{
string command;
command.append("SOUND ");
command.append(std::to_string(long long(level)));
command.append(",");
command.append(std::to_string(long long(doubleerval)));
command.append("\r\n");
return command;
}
string SetLimitFeed(double n)
{
string command;
command.append("LIMITFEED ");
command.append(std::to_string(long double(n)));
command.append("\r\n");
return command;
}
string SetSelftest()
{
string command;
command.append("SELFTEST ");
command.append("\r\n");
return command;
}
string PrintBuffer(char* m, char* n)
{
string command;
command.append("PRINT ");
command.append("1");
command.append(",");
command.append("1");
command.append("\r\n");
return command;
}
//¾í±ê¾í±ê¾í±êÄÚ ¾í±êÄÚÄÚÄÚÈÝÉè¼ÆÖ¸Áî
string PrintBar(int x, int y, int width, int height)
{
string command;
command.append("BAR ");
command.append(std::to_string(long long(x)));
command.append(",");
command.append(std::to_string(long long(y)));
command.append(",");
command.append(std::to_string(long long(width)));
command.append(",");
command.append(std::to_string(long long(height)));
command.append("\r\n");
return command;
}
string PrintBarcode(int x, int y, char* codeType, int height,int humanReadable,
int rotation, int narrow, int wide, char* code)
{
string command;
command.append("BARCODE ");
command.append(std::to_string(long long(x)));
command.append(",");
command.append(std::to_string(long long(y)));
command.append(",\"");
command.append(codeType);
command.append("\",");
command.append(std::to_string(long long(height)));
command.append(",");
command.append(std::to_string(long long(humanReadable)));
command.append(",");
command.append(std::to_string(long long(rotation)));
command.append(",");
command.append(std::to_string(long long(narrow)));
command.append(",");
command.append(std::to_string(long long(wide)));
command.append(",\"");
command.append(code);
command.append("\"\r\n");
return command;
}
string PrintBox(int xStart, int yStart, int xEnd, int yEnd, int lineThickness)
{
string command;
command.append("BOX ");
command.append(std::to_string(long long(xStart)));
command.append(",");
command.append(std::to_string(long long(yStart)));
command.append(",");
command.append(std::to_string(long long(yStart)));
command.append(",");
command.append(std::to_string(long long(yStart)));
command.append(",");
command.append(std::to_string(long long(yStart)));
command.append("\r\n");
return command;
}
string PrintBitmap(int x, int y, int width, int height, int mode, int bitMapData)
{
string command;
command.append("BITMAP ");
command.append(std::to_string(long long(x)));
command.append(",");
command.append(std::to_string(long long(y)));
command.append(",");
command.append(std::to_string(long long(width)));
command.append(",");
command.append(std::to_string(long long(height)));
command.append(",");
command.append(std::to_string(long long(mode)));
command.append(",");
command.append(std::to_string(long long(bitMapData)));
command.append("\r\n");
return command;
}
string PrintPutBmp(int x, int y, char* fileName)
{
string command;
command.append("PUTBMP ");
command.append(std::to_string(long long(x)));
command.append(",");
command.append(std::to_string(long long(y)));
command.append(",\"");
command.append(fileName);
command.append("\"\r\n");
return command;
}
string PrintPutPcx(int x, int y, char* fileName)
{
string command;
command.append("PUTPCX ");
command.append(std::to_string(long long(x)));
command.append(",");
command.append(std::to_string(long long(y)));
command.append(",\"");
command.append(fileName);
command.append("\"\r\n");
return command;
}
string PrintErase(int xStart, int yStart, int xWidth, int yHeight)
{
string command;
command.append("ERASE ");
command.append(std::to_string(long long(xStart)));
command.append(",");
command.append(std::to_string(long long(yStart)));
command.append(",");
command.append(std::to_string(long long(xWidth)));
command.append(",");
command.append(std::to_string(long long(yHeight)));
command.append("\r\n");
return command;
}
string PrintReverse(int xStart, int yStart, int xWidth, int yHeight)
{
string command;
command.append("REVERSE ");
command.append(std::to_string(long long(xStart)));
command.append(",");
command.append(std::to_string(long long(yStart)));
command.append(",");
command.append(std::to_string(long long(xWidth)));
command.append(",");
command.append(std::to_string(long long(yHeight)));
command.append("\r\n");
return command;
}
string PrintText(int x,int y, const char* font, int rotation, int xMulitiplication, int yMulitiplication, const char* content)
{
string command;
command.append("TEXT ");
command.append(std::to_string(long long(x)));
command.append(",");
command.append(std::to_string(long long(y)));
command.append(",\"");
command.append(font);
command.append("\",");
command.append(std::to_string(long long(rotation)));
command.append(",");
command.append(std::to_string(long long(xMulitiplication)));
command.append(",");
command.append(std::to_string(long long(yMulitiplication)));
command.append(",\"");
command.append(content);
command.append("\"\n");
return command;
}
#pragma once
//ϵͳÉ趨ָÁî
string SetSize(string m, string n);
string SetCashDrawer(double m);
string SetGap(double m, double n);
string SetOffset(double m);
string SetSpeed(string n);
string SetDensity(string n);
string SetDirection(double n);
string SetReference(int x, int y);
string SetShift(int n);
string SetCodePage(int n);
string SetCls();
string SetFeed(int n);
string SetBackFeedAndBackup(int n);
string SetFormFeed();
string SetHome();
string SetSound(int level, int doubleerval);
string SetLimitFeed(double n);
string SetSelftest();
string PrintBuffer(char* m, char* n);
//¾í±ê¾í±ê¾í±êÄÚ ¾í±êÄÚÄÚÄÚÈÝÉè¼ÆÖ¸Áî
string PrintBar(int x, int y, int width, int height);
string PrintBarcode( int x, int y, char* codeType, int height,int humanReadable,
int rotation, int narrow, int wide, char* code);
string PrintBox(int xStart, int yStart, int xEnd, int yEnd, int lineThickness);
string PrintBitmap(int x, int y, int width, int height, int mode, int bitMapData);
string PrintPutBmp(int x, int y, char* fileName);
string PrintPutPcx(int x, int y, char* fileName);
string PrintErase(int xStart, int yStart, int xWidth, int yHeight);
string PrintReverse(int xStart, int yStart, int xWidth, int yHeight);
string PrintText(int x,int y, const char* font, int rotation, int xMulitiplication, int yMulitiplication, const char* content);
#include "StdAfx.h"
#include "LoadDll.h"
#include "BPLAPrint.h"
#include "FECLabPrint.h"
#include "ComControl.h"
#define RESULT -1
#define LENTH_FMS 30
#define LENTH_FMS_80 -20
......@@ -23,6 +25,9 @@ extern int whole;
PrintClass m_printclass;
int heigth = 0;
vector<Function_Argv> m_label_args;
/*************FEC杯贴打印*****************/
ComControl comControl;
string printFecCommand;
/***************通用函数******************/
POS_Open VC_POS_Open = NULL;
......@@ -1791,6 +1796,114 @@ void _GetPrintIni(char inidata[])
}
break;
}
case 19:
{
if (ss.size()!=0)
{
m_printclass.shift = atoi(ss.c_str());
}
else
{
m_printclass.shift = 3;
}
break;
}
case 20:
{
if (ss.size()!=0)
{
m_printclass.direction = atoi(ss.c_str());
}
else
{
m_printclass.direction = 1;
}
break;
}
case 21:
{
if (ss.size()!=0)
{
m_printclass.dataBits = atoi(ss.c_str());
}
else
{
m_printclass.dataBits = 8;
}
break;
}
case 22:
{
if (ss.size()!=0)
{
m_printclass.parity = atoi(ss.c_str());
}
else
{
m_printclass.parity = 0;
}
break;
}
case 23:
{
if (ss.size()!=0)
{
m_printclass.stopBits = atoi(ss.c_str());
}
else
{
m_printclass.stopBits = 0;
}
break;
}
case 24:
{
if (ss.size()!=0)
{
m_printclass.param = atoi(ss.c_str());
}
else
{
m_printclass.param = 0;
}
break;
}
case 25:
{
if (ss.size()!=0)
{
m_printclass.gapm = atoi(ss.c_str());
}
else
{
m_printclass.gapm = 2;
}
break;
}
case 26:
{
if (ss.size()!=0)
{
m_printclass.gapn = atoi(ss.c_str());
}
else
{
m_printclass.gapn = 0;
}
break;
}
case 27:
{
if (ss.size()!=0)
{
m_printclass.comName = ss;
}
else
{
m_printclass.comName = "COM1";
}
break;
}
default:
{
m_printclass.printname = "Driver";
......@@ -1851,6 +1964,35 @@ int InitTscPort()
{
//清空参数缓存;
m_label_args.clear();
printFecCommand.clear();
if(m_printclass.label_type == string("2"))
{
comControl.SetComType(COM);
comControl.SetComSettings(m_printclass.comName,
m_printclass.bandRate,
m_printclass.dataBits,
m_printclass.parity,
m_printclass.stopBits,
m_printclass.param
);
string error;
if(comControl.OpenCom(error))
{
printFecCommand.append(SetSize(m_printclass.tsc_widgth,m_printclass.tsc_high));
printFecCommand.append(SetGap(m_printclass.gapm, m_printclass.gapn));
printFecCommand.append(SetOffset(8));
printFecCommand.append(SetSpeed(m_printclass.tsc_speed));
printFecCommand.append(SetDirection(1));
printFecCommand.append(SetReference(0,0));
printFecCommand.append(SetShift(m_printclass.shift));
printFecCommand.append(SetCodePage(437));
printFecCommand.append(SetCls());
}else{
return 0;
}
}
return 1;
}
......@@ -2210,6 +2352,12 @@ int PrintClose(char *page, char *num)
if(m_printclass.label_type.compare("1") == 0)
return PrintCloseBpla(page, num);
if(m_printclass.label_type.compare("2") == 0)
{
return _PrintFecLab(page,num);
}
return 0;
......@@ -2390,3 +2538,85 @@ bool _PrintBmp(char pszPath[], int nOrgx, int nMode,int alignMode)
return false;
}
}
//bool PrintFecLab()
//{
// bool result;
// string error;
// ComControl comControl;
// comControl.SetComSettings("COM3",9600,8,0,1,0);
// comControl.SetComType(COM);
// if(!comControl.OpenCom(error))
// {
// return false;
// }
// string printCommand;
// printCommand.append("");
// printf("s%",error);
// comControl.sendCommand(printCommand);
// comControl.CloseCom();
// return true;
//}
bool _OpenFecPort()
{
//if(m_printclass.label_type == string("FEC"))
//{
//}
comControl.SetComType(COM);
comControl.SetComSettings(m_printclass.comName,
m_printclass.bandRate,
m_printclass.dataBits,
m_printclass.parity,
m_printclass.stopBits,
m_printclass.param
);
string error;
if(comControl.OpenCom(error))
{
printFecCommand.append(SetSize(m_printclass.tsc_widgth,m_printclass.tsc_high));
printFecCommand.append(SetGap(m_printclass.gapm, m_printclass.gapn));
printFecCommand.append(SetOffset(8));
printFecCommand.append(SetSpeed(m_printclass.tsc_speed));
printFecCommand.append(SetDensity("8"));
printFecCommand.append(SetDirection(m_printclass.direction));
printFecCommand.append(SetReference(0,0));
printFecCommand.append(SetShift(m_printclass.shift));
printFecCommand.append(SetCodePage(437));
printFecCommand.append(SetCls());
}else{
VC_Log_WriteLog(1,"打开串口失败 ");
return false;
}
}
int _PrintFecLab(char* page, char* num)
{
VC_Log_WriteLog(1,"page x %s",page);
VC_Log_WriteLog(1,"num y %s",num);
printFecCommand.append(PrintBuffer(page,num));
comControl.sendCommand(printFecCommand);
comControl.CloseCom();
return 1;
}
void _PringFecLabText(int x, int y, char* fontType, int rotate, int xMultiplication, int yMultiplication, char* text)
{
string str1(fontType);
string str2(text);
//str1.append(fontType);
//str2.append(text);
string str = PrintText(x,y,str1.data(),rotate,xMultiplication,yMultiplication,str2.data());
printFecCommand.append(str);
}
void _PringFecLabBar(int x, int y, int width, int height)
{
printFecCommand.append(PrintBar(x,y,width,height));
}
void _PrintFecLabBmp()
{
}
\ No newline at end of file
diff a/LoadDll.cpp b/LoadDll.cpp (rejected hunks)
@@ -66,24 +66,27 @@
POS_KickOutDrawer VC_POS_KickOutDrawer = NULL;
POS_CutPaper VC_POS_CutPaper = NULL;
POS_StartDoc VC_POS_StartDoc = NULL;
POS_EndDoc VC_POS_EndDoc = NULL;
POS_EndSaveFile VC_POS_EndSaveFile = NULL;
POS_BeginSaveFile VC_POS_BeginSaveFile = NULL;
+
+POS_Raster_DownloadAndPrintBmp VC_POS_Raster_DownloadAndPrintBmp = NULL;
+
/***********ֻ֧�ֱ�׼��ӡģʽ(��ģʽ)�ĺ���************/
POS_S_SetAreaWidth VC_POS_S_SetAreaWidth = NULL;
POS_S_TextOut VC_POS_S_TextOut = NULL;
POS_S_DownloadAndPrintBmp VC_POS_S_DownloadAndPrintBmp = NULL;
POS_S_PrintBmpInRAM VC_POS_S_PrintBmpInRAM = NULL;
POS_S_PrintBmpInFlash VC_POS_S_PrintBmpInFlash = NULL;
POS_S_SetBarcode VC_POS_S_SetBarcode = NULL;
......@@ -358,12 +358,22 @@ typedef struct
int m_PrintSize; //打印的纸张设定
int type;
int m_nDays;
//标签打印机
int shift; //标签打印的偏移量
int direction; //标签打印的方向
int bandRate; //标签打印的波特率
int dataBits; //标签打印的数据位
int parity; //标签打印的奇偶校验
int stopBits; //标签打印的停止位
int param; //标签打印的流控制
double gapm; //标签的垂直间距
double gapn; //标签的垂直间距的偏移
string comName; //标签打印的端口号
string tsc_widgth; //标签打印的宽度
string tsc_high; //标签打印的高度
string tsc_speed; //走纸速度
string tsc_chroma; //打印弄度
//标签打印机
string label_type; //标签打印机打印类型 TSC; BPAL;
string label_type; //标签打印机打印类型 TSC; BPAL; FEC;
string label_parall; //标签打印机并口名字
string label_usb; //标签打印机usb的名字
string label_ip; //标签打印机IP
......@@ -411,7 +421,7 @@ int InitTscPort();
//x : 打印字体的x坐标;
//y : 打印字体的y坐标;建议传0;
//font_size : 字体大小;
//rotate : 字体选择角度;
//rotate : 字体旋转角度;
// 0 -> 0 degree
// 90-> 90 degree
// 180-> 180 degree
......@@ -431,4 +441,10 @@ int WinPrintlnTsc(int x, int y, int font_size, int rotate, int font_type, int hi
//每打印一页都要调用;
int PrintClose(char *page, char *num);
int _PrintFecLab(char* page, char* num);
bool _OpenFecPort();
void _PringFecLabText(int x, int y, char* fontType, int rotate, int xMultiplication, int yMultiplication, char* text);
void _PringFecLabBar(int x, int y, int width, int height);
void _PrintFecLabBmp();
#endif
......@@ -17,7 +17,7 @@
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <io.h>
#include "time.h"
#include "direct.h"
......
......@@ -184,3 +184,16 @@ extern "C" bool __declspec(dllexport)PrintBmp(char pszPath[], int nOrgx, int nMo
return _PrintBmp( pszPath, nOrgx, nMode,alignMode);//打印图片
}
extern "C" void __declspec(dllexport) PringFecLabText(int x, int y, char* fontType, int rotate, int xMultiplication, int yMultiplication, char* text)
{
_PringFecLabText(x, y, fontType, rotate, xMultiplication, yMultiplication, text);
}
extern "C" void __declspec(dllexport) PringFecLabBar(int x, int y, int width, int height)
{
_PringFecLabBar( x, y, width, height);
}
extern "C" void __declspec(dllexport) PrintFecLabBmp()
{
_PrintFecLabBmp();
}
......@@ -137,6 +137,8 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ComControl.cpp" />
<ClCompile Include="FECLabPrint.cpp" />
<ClCompile Include="fmposdll.cpp" />
<ClCompile Include="LoadDll.cpp" />
<ClCompile Include="StdAfx.cpp">
......@@ -156,6 +158,8 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="BPLAPrint.h" />
<ClInclude Include="ComControl.h" />
<ClInclude Include="FECLabPrint.h" />
<ClInclude Include="LoadDll.h" />
<ClInclude Include="StdAfx.h" />
</ItemGroup>
......
......@@ -24,6 +24,12 @@
<ClCompile Include="StdAfx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="FECLabPrint.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ComControl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="LoadDll.h">
......@@ -35,6 +41,12 @@
<ClInclude Include="BPLAPrint.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="FECLabPrint.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ComControl.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="fmsdll.def">
......
......@@ -15,3 +15,6 @@ EXPORTS
TSCWinPrintPage @13
TSCInit @14
PrintBmp @15
PringFecLabText @18
PringFecLabBar @19
PrintFecLabBmp @20
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment