在一個資料匯出的dll基礎上增加資料串口傳出的功能(將Sn通過串口發送出去),求教大神該怎么去改,附上當前資料匯出的dll源檔案,在線等!
// CommData.cpp : 定義 DLL 應用程式的匯出函式。
//
#include "stdafx.h"
#pragma once
#ifdef Data_API
#else
#define Data_API extern "C" _declspec(dllimport)
#endif
#include <string>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//發送產品上掃描到的資料、
//引數 Mo 工單號 (注:如果用戶未更改生產檔案內的工單號時,默認為機臺號)
//引數 Sn 掃描到的資料陣列
//引數 snNum 掃描到的資料個數 格式為:SN1,SN2,SN3 ==3
//回傳值 //成功 回傳 TRUE //失敗 回傳 FALSE
Data_API bool SenScanData(string Mo,string Sn[],int snNum);
bool SenScanData( string Mo,string Sn[],int snNum )
{
return TRUE;
}
//引數1 dlgData 額外的界面資料
//引數3 machineData 機器產生資料
//PrName 制程式
//StarTime 開始作業時間 2017/9/5 13:30
//StopTime 結束作業時間 2017/9/5 14:30
//MNum 機臺編號
//CodeType
//引數2 addDataNum 額外的資料 數量
Data_API bool SenData(string dlgData[],string machineData[],string Sn[],int snNum,string FilePath);
bool SenData( string dlgData[],string machineData[],string Sn[],int snNum,string FilePath )
{
//General1=
string str;
ofstream ofst;
ofst.open(FilePath,ios::app);
str = "General1="+dlgData[1]; // 工單號
ofst << str;
str = "\nGeneral2="+dlgData[2]; // 制程
ofst << str;
str = "\nGeneral3="+machineData[2]; // 開始時間
ofst << str;
str = "\nGeneral4="+machineData[3]; // 結束時間
ofst << str;
str = "\nGeneral5="+dlgData[0]; // 機臺編號
ofst << str;
str = "\nGeneral6="+dlgData[3]; // CODE類型
ofst << str;
str = "\nGeneral7="+Sn[0]; // 條碼
for(int i=1;i<(snNum-1);i++)
{
str = str+","+Sn[i+1];
}
ofst << str;
str = "\nGeneral8="+machineData[0];// 程式名稱
ofst << str;
str = "\nGeneral9="+dlgData[4]; // 作業數量 (總生產數量)
ofst << str;
str = "\nGeneral10="+machineData[4]; // 生產的第幾個產品
ofst << str;
str = "\nGeneral11="+machineData[1]; // 作業員工號
ofst << str;
str = "\nGeneral12="+dlgData[5]; // 冶具編號
ofst << str;
str = "\nGeneral13="+machineData[5]; // 正反面
ofst << str;
str = "\nGeneral14="+machineData[6]; // PCS序號
ofst << str;
str = "\nMachine1="+machineData[7]; // 這塊板總共貼了幾個點
ofst << str;
str = "\nMachine2="+dlgData[6]; // 輔數1編號
ofst << str;
str = "\nMachine3="+dlgData[7]; // 輔數2編號
ofst << str;
str = "\nMachine4="+dlgData[8]; // 吸嘴1編號
ofst << str;
str = "\nMachine5="+dlgData[9]; // 吸嘴2編號
ofst << str;
str = "\nMachine6="+machineData[8]; // 拋料次數
ofst << str;
str = "\nMachine7="+machineData[9]; // 拋料率
ofst << str;
ofst.close();
OutputDebugString("Dll 輸出完成");
return true;
}
uj5u.com熱心網友回復:
Serial Communications in Win32Serial Communications
uj5u.com熱心網友回復:
用SenData函式就可以呀uj5u.com熱心網友回復:
您是說代碼中這個函式就能實作?求詳細指點一下
uj5u.com熱心網友回復:
你是要在SenScanData函式里面實作發送sn號吧,那么需要打開串口,配置好串口引數,之后發送sn號,然后關閉串口,Windows下具體做法:CreateFile創建串口,SetCommState設定屬性,WriteFile發送資料,CloseHandle關閉串口。
具體的代碼網上可以找到的,你可以查一下。
uj5u.com熱心網友回復:
頂一下樓上,引數一定要配置正確uj5u.com熱心網友回復:
主要就是操作串口的方法,然后把資料轉換成BYTE陣列等轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/69983.html
標籤:進程/線程/DLL
