재전송 기능 추가

master V3.2.0
DESKTOP-999R8N3\CJY 2023-11-08 17:54:53 +09:00
parent f17a8ae83e
commit a151bd378b
16 changed files with 3124 additions and 2217 deletions

View File

@ -822,7 +822,6 @@ namespace ITC81DB_0H.Controls
switch (temp)
{
case Define.E_MenuBottomConfiguration.SerialCOM1:
this.ParentForm.ParentForm.CloseSerialCOM1();
this.comboBoxSerialBaudRate.SelectedIndexChanged -= new EventHandler(this.comboBoxSerialBaudRate_SelectedIndexChanged);
this.comboBoxSerialBaudRate.SelectedIndex = 4;
this.comboBoxSerialBaudRate.SelectedIndexChanged += new EventHandler(this.comboBoxSerialBaudRate_SelectedIndexChanged);

View File

@ -25,6 +25,9 @@ namespace ITC81DB_0H
#region CommunicationCommand
public class CommunicationCommand
{
// 운전데이터 Respone
public static readonly string StartDataCMD = "Sr0";
// 불량알람(레벨)
public static readonly string AlarmNgLevel = "Caa00";
// 불량알람 해지
@ -1554,6 +1557,60 @@ namespace ITC81DB_0H
}
#endregion
#region CommunicationRespone
public class CommunicationRespone
{
#region Field
private bool m_IsFirst;
private string m_TransactionID;
private string m_TransferCount;
#endregion
#region Constructor
public CommunicationRespone()
{
this.Initialization();
}
#endregion
#region Property
public bool IsFirst
{
get { return this.m_IsFirst; }
set { this.m_IsFirst = value; }
}
/// <summary>
/// Data ID (0~9)
/// </summary>
public string TransactionID
{
get { return this.m_TransactionID; }
set { this.m_TransactionID = value; }
}
/// <summary>
/// 재전송 CNT (0~9)
/// </summary>
public string TransferCount
{
get { return this.m_TransferCount; }
set { this.m_TransferCount = value; }
}
#endregion
#region Method
public void Initialization()
{
this.IsFirst = false;
this.TransactionID = "a";
this.TransferCount = "a";
}
#endregion
}
#endregion
public class AlarmList
{
#region Field

View File

@ -46,6 +46,8 @@
this.timerEthernetPing = new System.Windows.Forms.Timer();
this.smartTimerLogout = new SmartX.SmartTimer(this.components);
this.timerUserList = new System.Windows.Forms.Timer();
this.smartThreadSerialPort2OverRun = new SmartX.SmartThread(this.components);
this.smartThreadSerialPort2Read = new SmartX.SmartThread(this.components);
((System.ComponentModel.ISupportInitialize)(this.smartForm)).BeginInit();
this.SuspendLayout();
//
@ -95,6 +97,7 @@
this.smartSerialPort2.STXCodes = null;
this.smartSerialPort2.TailErrorCodeOffset = 0;
this.smartSerialPort2.OnReadQueueEvent += new SmartX.SmartSerialPort.ReceiveDataHandler(this.smartSerialPort2_OnReadQueueEvent);
this.smartSerialPort2.OnPortError += new SmartX.SmartSerialPort.PortErrorHandler(this.smartSerialSerialPort2_OnPortError);
//
// smartSerialPort1
//
@ -209,6 +212,16 @@
this.timerUserList.Interval = 1000;
this.timerUserList.Tick += new System.EventHandler(this.timerUserList_Tick);
//
// smartThreadSerialPort2OverRun
//
this.smartThreadSerialPort2OverRun.Priority = System.Threading.ThreadPriority.Normal;
this.smartThreadSerialPort2OverRun.UIThreadFunction += new SmartX.SmartThread.UIThreadHandler(this.smartThreadSerialPort2Read_UIThreadFunction);
//
// smartThreadSerialPort2Read
//
this.smartThreadSerialPort2Read.Priority = System.Threading.ThreadPriority.Normal;
this.smartThreadSerialPort2Read.UIThreadFunction += new SmartX.SmartThread.UIThreadHandler(this.smartThreadSerialPort2Read_UIThreadFunction);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@ -242,6 +255,8 @@
private System.Windows.Forms.Timer timerEthernetPing;
private SmartX.SmartTimer smartTimerLogout;
private System.Windows.Forms.Timer timerUserList;
private SmartX.SmartThread smartThreadSerialPort2OverRun;
private SmartX.SmartThread smartThreadSerialPort2Read;
}
}

View File

@ -18,14 +18,15 @@ using InModbus;
using ITC81DB_2H.Datastore;
using ITC81DB_0H.Part11_UserManager;
using ITC81DB_0H.Part11_Encryption;
using ITC81DB_0H.SerialManager;
namespace ITC81DB_0H.Forms
{
public partial class FormMain : Form
{
#region Field
public static string DisplayVersion = "3.1.2";
public static string ReleaseDate = "2023.10.31";
public static string DisplayVersion = "3.2.0";
public static string ReleaseDate = "2023.11.08";
private SmartSplash SmartSplashProgramLoad;
public bool IsCommunicationLogOpen;
@ -51,6 +52,16 @@ namespace ITC81DB_0H.Forms
public int FlagAutomaticLogoutWarningTime;
public bool IsLogProcessing;
// 재전송 기능
public int MissingCommIDCount;
public int CommID;
public bool FlagSerialDll = true;
private string ComPortMainToLCD;
private Queue<string> QueueCommunicationRecive; // 큐 통신 데이터용
private int FlagComRetry3th; // 3회 재전송 횟수
public Queue<string> QueueOverRun = new Queue<string>();
private int IndexOverRun = 0;
private byte[] ClientSendDatabyteArray;
private string ClientSendDataString;
@ -183,6 +194,8 @@ namespace ITC81DB_0H.Forms
private JudgmentResult CurrentJudgmentResult;
// Dll User_Name List
public List<string> ListDllUserName;
// Communication Respone
private CommunicationRespone CurrentComRespone;
// HM Handshake를 위한 함수
private int HMCOM1_Step;
@ -383,7 +396,11 @@ namespace ITC81DB_0H.Forms
this.UpdateValue = 0;
this.IsOPCModbusUsing = false;
this.IsLogProcessing = false;
this.FlagComRetry3th = 0;
this.MissingCommIDCount = 0;
this.CommID = 0;
this.QueueCommunicationRecive = new Queue<string>();
this.CurrentAlarmList = new AlarmList();
this.EventAlarmStateChange += new Define.EventHandlerAlarmStateChange(this.CurrentAlarmList_Change);
@ -433,6 +450,8 @@ namespace ITC81DB_0H.Forms
this.PathHeaderFolder = this.PathLaunchFolder + "Header\\";
PathBinFolder = this.PathLaunchFolder + "Bin\\";
this.CurrentComRespone = new CommunicationRespone();
this.ListDllUserName = new List<string>();
this.ListDllUserName.Clear();
@ -524,6 +543,18 @@ namespace ITC81DB_0H.Forms
pathSDCardSystemFileFolder.Delete();
}
// COM port 설정
this.smartSerialPort2.PortNo = SmartSerialPort.COMPORTNO.COM2;
this.ComPortMainToLCD = "COM2:";
if (this.FlagSerialDll == true)
{
SerialMgrComm.IntializeSerialManager();
SerialMgrComm.SerialPortMessageReceive += this.SerialPort_MessageReceive;
SerialMgrComm.SerialPortErrMessageReceive += this.SerialPort_ErrMessageReceive;
}
// Data 폴더 생성
if (Directory.Exists(this.PathDataFolder) == false)
Directory.CreateDirectory(this.PathDataFolder);
@ -562,8 +593,7 @@ namespace ITC81DB_0H.Forms
}
// 통신 포트 설정
if (this.smartSerialPort3.IsOpen == true)
this.smartSerialPort3.Close();
this.CloseSerialCOM3();
// STXANDETX
this.ChangeSerialCOM3FrameSeparateType(Define.E_SeparateType.STXANDETX);
@ -1050,6 +1080,46 @@ namespace ITC81DB_0H.Forms
this.FlagThreadMessage1 = false;
}
}
private bool UI_Invoke(ThreadStart invoker)
{
try
{
if (this.InvokeRequired)
{
if (this.IsDisposed)
return true;
this.Invoke(invoker);
}
else
{
invoker();
}
return true;
}
catch (Exception e)
{
return false;
}
}
private void SerialPort_MessageReceive(object data)
{
this.UI_Invoke(delegate
{
this.SerialReceiveData(data.ToString());
});
}
private void SerialPort_ErrMessageReceive(object data)
{
this.UI_Invoke(delegate
{
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Dll(Err MSG)", DateTime.Now, data));
});
}
/// <summary>
/// Set Mode
@ -1565,16 +1635,25 @@ namespace ITC81DB_0H.Forms
}
#region Uart Communication
private void OpenSmartUartLink()
private void OpenSmartSerialPort2()
{
string fullPath = "";
DateTime dt = DateTime.Now;
try
{
if (this.FlagSerialDll == false)
{
if (this.smartSerialPort2.IsOpen == false)
this.smartSerialPort2.Open();
}
else
{
// Port : COM2
// Baudrate : 115200
SerialMgrComm.serialPortOpen(this.ComPortMainToLCD, 115200, 0, 0, 8);
}
}
catch
{
}
@ -1594,9 +1673,12 @@ namespace ITC81DB_0H.Forms
//this.IsErrorLogOpen = true;
#endregion
}
public void CloseSmartUartLink()
public void CloseSmartSerialPort2()
{
if (this.FlagSerialDll == false)
this.smartSerialPort2.Close();
else
SerialMgrComm.serialPortClose("COM2:");
}
private bool SizeCheck(string cmd, string strTemp)
@ -1794,8 +1876,13 @@ namespace ITC81DB_0H.Forms
sb.Append(chkSum);
if (this.FlagSerialDll == false)
{
if (this.smartSerialPort2.IsOpen == true)
this.smartSerialPort2.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
}
else
SerialMgrComm.serialPortMessage(this.ComPortMainToLCD, sb.ToString());
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
@ -1823,8 +1910,13 @@ namespace ITC81DB_0H.Forms
sb.Append(chkSum);
if (this.FlagSerialDll == false)
{
if (this.smartSerialPort2.IsOpen == true)
this.smartSerialPort2.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
}
else
SerialMgrComm.serialPortMessage(this.ComPortMainToLCD, sb.ToString());
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
@ -1875,8 +1967,14 @@ namespace ITC81DB_0H.Forms
for (int i = 0; i < byteCollection.Count; i++)
byteData[i] = byteCollection[i];
if (this.FlagSerialDll == false)
{
if (this.smartSerialPort2.IsOpen == true)
this.smartSerialPort2.WriteFrame(byteData);
}
else
SerialMgrComm.serialPortMessageByte(this.ComPortMainToLCD, byteData, byteData.Length);
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
@ -1891,28 +1989,38 @@ namespace ITC81DB_0H.Forms
return ret;
}
private void ReceiveData()
private int TransferDataRespone(string command, string id, string transactionID, string TransferCount, string respone)
{
int ret = 0;
string strTemp = "";
byte[] readByte;
string chkSum = "cc";
StringBuilder sb = new StringBuilder();
SmartSerialPort.FRAMEDATAREADSTATUS receiveDataState = SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY;
sb.Append(command);
sb.Append(transactionID);
sb.Append(TransferCount);
sb.Append(respone);
try
{
receiveDataState = this.smartSerialPort2.ReadQueue(out readByte);
strTemp = Encoding.Default.GetString(readByte, 0, readByte.Length);
}
catch
{
return;
}
chkSum = this.Checksumcalculator(sb.ToString());
if ((receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY) || (receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.FAILDATA))
sb.Append(chkSum);
if (this.FlagSerialDll == false)
{
return;
if (this.smartSerialPort2.IsOpen == true)
this.smartSerialPort2.WriteFrame(sb.ToString(), SmartX.SmartSerialPort.CODETYPES.ASCIICODE);
}
else
SerialMgrComm.serialPortMessage(this.ComPortMainToLCD, sb.ToString());
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.WriteString(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));
return ret;
}
private void ReceiveData(string strTemp)
{
int ret = 0;
try
{
@ -2086,6 +2194,8 @@ namespace ITC81DB_0H.Forms
this.CurrentSystemStatus.Equipment = Define.E_EquipmentStatus.Stop;
this.SetTrackingHistoryData(Define.E_TrackingOperation.Stop, "");
this.CommID = 0;
// OPT1(액트라 - 안리쯔 금속검출기)
if (this.SystemConfig1.SerialCOM1Mode == 14)
this.TransferSerialCOM1(this.Transfer_14_OPT1("13"));
@ -2944,7 +3054,7 @@ namespace ITC81DB_0H.Forms
return ret;
}
// 운전시 중량
private int ReceiveCommand(string cmd, string lane, string dataID, string transferCount, string receiveData)
private int ReceiveCommand(string cmd, string lane, string transactionID, string transferCount, string receiveData)
{
int ret = 0;
int temp = 0;
@ -2966,7 +3076,7 @@ namespace ITC81DB_0H.Forms
//this.CurrentWeightData.ProductionSpeed = int.Parse(receiveData.Substring(15, 4).Trim());
this.CurrentWeightData.WeightSum(this.CurrentWeightData.JudgmentStatus);
this.CurrentWeightData.SetDataIDTransferCount(dataID, transferCount);
this.CurrentWeightData.SetDataIDTransferCount(transactionID, transferCount);
this.CurrentWeightData.Status = Define.E_WeightStatus.WeightChange;
#endregion
@ -2983,7 +3093,7 @@ namespace ITC81DB_0H.Forms
this.CurrentWeightData.ProductionSpeed = int.Parse(receiveData.Substring(19, 4).Trim());
this.CurrentWeightData.WeightSum(this.CurrentWeightData.JudgmentStatus);
this.CurrentWeightData.SetDataIDTransferCount(dataID, transferCount);
this.CurrentWeightData.SetDataIDTransferCount(transactionID, transferCount);
this.CurrentWeightData.Status = Define.E_WeightStatus.WeightChange;
#endregion
@ -2992,8 +3102,21 @@ namespace ITC81DB_0H.Forms
break;
}
// 통신 제대로 받으면 ACK
this.TransferData(string.Format("{0}{1}{2}{3}", CommunicationCommand.RunWeightData, (int)Define.E_ResponseData.ACK, dataID, transferCount), CommunicationID.MainBoard);
//// 통신 제대로 받으면 ACK
//this.TransferData(string.Format("{0}{1}{2}{3}", CommunicationCommand.RunWeightData, (int)Define.E_ResponseData.ACK, dataID, transferCount), CommunicationID.MainBoard);
if (this.CommID % 10 != int.Parse(transactionID))
{
this.MissingCommIDCount++;
this.ChildFormMainDisplay.labelMissingCount.Text = this.MissingCommIDCount.ToString();
}
else
this.CommID++;
if (this.CurrentComRespone.TransactionID != transactionID)
{
this.CurrentComRespone.TransactionID = transactionID;
this.CurrentComRespone.TransferCount = transferCount;
if (this.CurrentWeightData.WeightString.Trim() == "-9999" || this.CurrentWeightData.WeightString.Trim() == "9999"
|| this.CurrentWeightData.WeightString.Trim() == "99999")
@ -3939,6 +4062,7 @@ namespace ITC81DB_0H.Forms
default:
break;
}
}
break;
default:
break;
@ -6238,71 +6362,116 @@ namespace ITC81DB_0H.Forms
#region Serial COM1
public void OpenSerialCOM1()
{
int baudrate = 9600;
if (this.SystemConfig1.SerialCOM1Mode == 0 || this.SystemConfig1.SerialCOM1Mode == 16)
return;
if (this.smartSerialPort1.IsOpen == true)
this.smartSerialPort1.Close();
this.CloseSerialCOM1();
switch (this.SystemConfig1.SerialCOM1BaudRate)
{
case 0:
this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
baudrate = 9600;
break;
case 1:
this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._19200bps;
baudrate = 19200;
break;
case 2:
this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._38400bps;
baudrate = 38400;
break;
case 3:
this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._57600bps;
baudrate = 57600;
break;
case 4:
this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._115200bps;
baudrate = 115200;
break;
default:
this.smartSerialPort1.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
baudrate = 9600;
break;
}
if (this.FlagSerialDll == false)
{
this.smartSerialPort1.Open();
}
else
{
// Port : COM1
SerialMgrComm.serialPortOpen("COM1:", baudrate, 0, 0, 8);
}
}
public void CloseSerialCOM1()
{
if (this.FlagSerialDll == false)
this.smartSerialPort1.Close();
else
SerialMgrComm.serialPortClose("COM1:");
}
public bool CheckOpenCOM1()
{
if (this.FlagSerialDll == false)
{
if (this.smartSerialPort1.IsOpen == true)
return true;
else
return false;
}
else
return true;
}
public void TransferDirectSerialCOM1(string strTemp)
{
if (this.SystemConfig1.SerialCOM1Mode == 3 && this.SystemConfig1.StatisticsPrintFormat == 1)
{
byte[] strByte = Encoding.GetEncoding("ks_c_5601-1987").GetBytes(strTemp);
if (this.FlagSerialDll == false)
this.smartSerialPort1.WriteNoneFrame(strByte);
else
SerialMgrComm.serialPortMessageByte("COM1:", strByte, strByte.Length);
}
else
{
if (this.FlagSerialDll == false)
this.smartSerialPort1.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
else
SerialMgrComm.serialPortMessageRaw("COM1:", strTemp);
}
}
public void TransferDirectSerialCOM1(byte[] buffer)
{
if (this.FlagSerialDll == false)
this.smartSerialPort1.WriteNoneFrame(buffer);
else
SerialMgrComm.serialPortMessageByte("COM1:", buffer, buffer.Length);
}
public void TransferSerialCOM1(string strTemp)
{
if (this.smartSerialPort1.IsOpen == true)
{
if (this.SystemConfig1.TransmissionDelayTimeCOM1 == 0)
{
if (this.SystemConfig1.SerialCOM1Mode == 3 && this.SystemConfig1.StatisticsPrintFormat == 1)
{
byte[] strByte = Encoding.GetEncoding("ks_c_5601-1987").GetBytes(strTemp);
if (this.FlagSerialDll == false)
this.smartSerialPort1.WriteNoneFrame(strByte);
else
SerialMgrComm.serialPortMessageByte("COM1:", strByte, strByte.Length);
}
else
{
if (this.FlagSerialDll == false)
this.smartSerialPort1.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
else
SerialMgrComm.serialPortMessageRaw("COM1:", strTemp);
}
}
else
{
@ -6310,25 +6479,28 @@ namespace ITC81DB_0H.Forms
this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM1);
}
}
}
public void TransferSerialCOM1(byte[] buffer)
{
if (this.smartSerialPort1.IsOpen == true)
{
if (this.SystemConfig1.TransmissionDelayTimeCOM1 == 0)
{
if (this.FlagSerialDll == false)
this.smartSerialPort1.WriteNoneFrame(buffer);
else
SerialMgrComm.serialPortMessageByte("COM1:", buffer, buffer.Length);
}
else
{
this.QueueCOM1.Enqueue(buffer);
this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM1);
}
}
}
public void ChangeSerialCOM1FrameSeparateType(Define.E_SeparateType type)
{
if (this.FlagSerialDll == true)
return;
// 통신 포트 설정
if (this.smartSerialPort1.IsOpen == true)
this.smartSerialPort1.Close();
this.CloseSerialCOM1();
if (type == Define.E_SeparateType.ETXONLY)
{
@ -6363,79 +6535,133 @@ namespace ITC81DB_0H.Forms
#region Serial COM3
public void OpenSerialCOM3()
{
int baudrate = 9600;
if (this.SystemConfig1.SerialCOM3Mode == 0 || this.SystemConfig1.SerialCOM3Mode == 16)
return;
if (this.smartSerialPort3.IsOpen == true)
this.smartSerialPort3.Close();
this.CloseSerialCOM3();
switch (this.SystemConfig1.SerialCOM3BaudRate)
{
case 0:
this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
baudrate = 9600;
break;
case 1:
this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._19200bps;
baudrate = 19200;
break;
case 2:
this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._38400bps;
baudrate = 38400;
break;
case 3:
this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._57600bps;
baudrate = 57600;
break;
case 4:
this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._115200bps;
baudrate = 115200;
break;
default:
this.smartSerialPort3.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
baudrate = 9600;
break;
}
if (this.FlagSerialDll == false)
{
this.smartSerialPort3.Open();
}
else
{
// Port : COM3
SerialMgrComm.serialPortOpen("COM3:", baudrate, 0, 0, 8);
}
}
public void CloseSerialCOM3()
{
if (this.FlagSerialDll == false)
this.smartSerialPort3.Close();
else
SerialMgrComm.serialPortClose("COM3:");
}
public bool CheckOpenCOM3()
{
if (this.FlagSerialDll == false)
{
if (this.smartSerialPort3.IsOpen == true)
return true;
else
return false;
}
else
return true;
}
public void TransferDirectSerialCOM3(string strTemp)
{
if (this.SystemConfig1.SerialCOM3Mode == 3 && this.SystemConfig1.StatisticsPrintFormat == 1)
{
byte[] strByte = Encoding.GetEncoding("ks_c_5601-1987").GetBytes(strTemp);
if (this.FlagSerialDll == false)
this.smartSerialPort3.WriteNoneFrame(strByte);
else
SerialMgrComm.serialPortMessageByte("COM3:", strByte, strByte.Length);
}
else
{
if (this.FlagSerialDll == false)
this.smartSerialPort3.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
else
SerialMgrComm.serialPortMessageRaw("COM3:", strTemp);
}
}
public void TransferDirectSerialCOM3(byte[] buffer)
{
if (this.FlagSerialDll == false)
this.smartSerialPort3.WriteNoneFrame(buffer);
else
SerialMgrComm.serialPortMessageByte("COM3:", buffer, buffer.Length);
}
public void TransferDirectSerialCOM3RawData(string strTemp)
{
if (this.FlagSerialDll == false)
this.smartSerialPort3.RawSerialPort.Write(strTemp);
else
SerialMgrComm.serialPortMessageRaw("COM3:", strTemp);
}
public void TransferDirectSerialCOM3RawData(byte[] buffer)
{
if (this.FlagSerialDll == false)
this.smartSerialPort3.RawSerialPort.Write(buffer, 0, buffer.Length);
else
SerialMgrComm.serialPortMessageByte("COM3:", buffer, buffer.Length);
}
public void TransferSerialCOM3(string strTemp)
{
if (this.smartSerialPort3.IsOpen == true)
{
if (strTemp == "" || strTemp == null)
return;
if (this.SystemConfig1.TransmissionDelayTimeCOM3 == 0)
{
if (this.SystemConfig1.SerialCOM3Mode == 3 && this.SystemConfig1.StatisticsPrintFormat == 1)
{
byte[] strByte = Encoding.GetEncoding("ks_c_5601-1987").GetBytes(strTemp);
if (this.FlagSerialDll == false)
this.smartSerialPort3.WriteNoneFrame(strByte);
else
SerialMgrComm.serialPortMessageByte("COM3:", strByte, strByte.Length);
}
else
{
if (this.FlagSerialDll == false)
this.smartSerialPort3.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
else
SerialMgrComm.serialPortMessageRaw("COM3:", strTemp);
}
}
else
{
@ -6443,28 +6669,31 @@ namespace ITC81DB_0H.Forms
this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM3);
}
}
}
public void TransferSerialCOM3(byte[] buffer)
{
if (this.smartSerialPort3.IsOpen == true)
{
if (this.SystemConfig1.TransmissionDelayTimeCOM3 == 0)
{
if (this.FlagSerialDll == false)
this.smartSerialPort3.WriteNoneFrame(buffer);
else
SerialMgrComm.serialPortMessageByte("COM3:", buffer, buffer.Length);
}
else
{
this.QueueCOM3.Enqueue(buffer);
this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM3);
}
}
}
public void TransferSerialCOM3RawData(byte[] buffer)
{
if (this.smartSerialPort3.IsOpen == true)
{
if (this.SystemConfig1.TransmissionDelayTimeCOM3 == 0)
{
if (this.FlagSerialDll == false)
//RawSerialPort 기능을 사용하여 데이터를 전송
this.smartSerialPort3.RawSerialPort.Write(buffer, 0, buffer.Length);
else
SerialMgrComm.serialPortMessageByte("COM3:", buffer, buffer.Length);
}
else
{
@ -6472,7 +6701,6 @@ namespace ITC81DB_0H.Forms
this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM3);
}
}
}
public void ReceiveSerialCOM3()
{
int ret = 0;
@ -6503,9 +6731,11 @@ namespace ITC81DB_0H.Forms
public void ChangeSerialCOM3FrameSeparateType(Define.E_SeparateType type)
{
if (this.FlagSerialDll == true)
return;
// 통신 포트 설정
if (this.smartSerialPort3.IsOpen == true)
this.smartSerialPort3.Close();
this.CloseSerialCOM3();
if (type == Define.E_SeparateType.ETXONLY)
{
@ -6548,71 +6778,116 @@ namespace ITC81DB_0H.Forms
#region Serial COM4
public void OpenSerialCOM4()
{
int baudrate = 9600;
if (this.SystemConfig1.SerialCOM4Mode == 0 || this.SystemConfig1.SerialCOM4Mode == 16)
return;
if (this.smartSerialPort4.IsOpen == true)
this.smartSerialPort4.Close();
this.CloseSerialCOM4();
switch (this.SystemConfig1.SerialCOM4BaudRate)
{
case 0:
this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
baudrate = 9600;
break;
case 1:
this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._19200bps;
baudrate = 19200;
break;
case 2:
this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._38400bps;
baudrate = 38400;
break;
case 3:
this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._57600bps;
baudrate = 57600;
break;
case 4:
this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._115200bps;
baudrate = 115200;
break;
default:
this.smartSerialPort4.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
baudrate = 9600;
break;
}
if (this.FlagSerialDll == false)
{
this.smartSerialPort4.Open();
}
else
{
// Port : COM4
SerialMgrComm.serialPortOpen("COM4:", baudrate, 0, 0, 8);
}
}
public void CloseSerialCOM4()
{
if (this.FlagSerialDll == false)
this.smartSerialPort4.Close();
else
SerialMgrComm.serialPortClose("COM4:");
}
public bool CheckOpenCOM4()
{
if (this.FlagSerialDll == false)
{
if (this.smartSerialPort4.IsOpen == true)
return true;
else
return false;
}
else
return true;
}
public void TransferDirectSerialCOM4(string strTemp)
{
if (this.SystemConfig1.SerialCOM4Mode == 3 && this.SystemConfig1.StatisticsPrintFormat == 1)
{
byte[] strByte = Encoding.GetEncoding("ks_c_5601-1987").GetBytes(strTemp);
if (this.FlagSerialDll == false)
this.smartSerialPort4.WriteNoneFrame(strByte);
else
SerialMgrComm.serialPortMessageByte("COM4:", strByte, strByte.Length);
}
else
{
if (this.FlagSerialDll == false)
this.smartSerialPort4.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
else
SerialMgrComm.serialPortMessageRaw("COM4:", strTemp);
}
}
public void TransferDirectSerialCOM4(byte[] buffer)
{
if (this.FlagSerialDll == false)
this.smartSerialPort4.WriteNoneFrame(buffer);
else
SerialMgrComm.serialPortMessageByte("COM4:", buffer, buffer.Length);
}
public void TransferSerialCOM4(string strTemp)
{
if (this.smartSerialPort4.IsOpen == true)
{
if (this.SystemConfig1.TransmissionDelayTimeCOM4 == 0)
{
if (this.SystemConfig1.SerialCOM4Mode == 3 && this.SystemConfig1.StatisticsPrintFormat == 1)
{
byte[] strByte = Encoding.GetEncoding("ks_c_5601-1987").GetBytes(strTemp);
if (this.FlagSerialDll == false)
this.smartSerialPort4.WriteNoneFrame(strByte);
else
SerialMgrComm.serialPortMessageByte("COM4:", strByte, strByte.Length);
}
else
{
if (this.FlagSerialDll == false)
this.smartSerialPort4.WriteNoneFrame(strTemp, SmartSerialPort.CODETYPES.ASCIICODE);
else
SerialMgrComm.serialPortMessageRaw("COM4:", strTemp);
}
}
else
{
@ -6620,25 +6895,28 @@ namespace ITC81DB_0H.Forms
this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM4);
}
}
}
public void TransferSerialCOM4(byte[] buffer)
{
if (this.smartSerialPort4.IsOpen == true)
{
if (this.SystemConfig1.TransmissionDelayTimeCOM4 == 0)
{
if (this.FlagSerialDll == false)
this.smartSerialPort4.WriteNoneFrame(buffer);
else
SerialMgrComm.serialPortMessageByte("COM4:", buffer, buffer.Length);
}
else
{
this.QueueCOM4.Enqueue(buffer);
this.CreateTimer(Define.E_MenuBottomConfiguration.SerialCOM4);
}
}
}
public void ChangeSerialCOM4FrameSeparateType(Define.E_SeparateType type)
{
if (this.FlagSerialDll == true)
return;
// 통신 포트 설정
if (this.smartSerialPort4.IsOpen == true)
this.smartSerialPort4.Close();
this.CloseSerialCOM4();
if (type == Define.E_SeparateType.ETXONLY)
{
@ -11058,31 +11336,6 @@ namespace ITC81DB_0H.Forms
UserManager.UserManager_AutoLogoutSetTimeout(this.SystemConfig2.UserAutomaticLogout, this.FlagAutomaticLogoutWarningTime);
}
private bool UI_Invoke(ThreadStart invoker)
{
try
{
if (this.InvokeRequired)
{
if (this.IsDisposed)
return true;
this.Invoke(invoker);
}
else
{
invoker();
}
return true;
}
catch (Exception e)
{
return false;
}
}
/// <summary>
/// Set User
/// </summary>
@ -12307,7 +12560,12 @@ namespace ITC81DB_0H.Forms
this.CreateForm();
// 메인 통신 OPEN
this.OpenSmartUartLink();
this.OpenSmartSerialPort2();
// 통신 버퍼용
this.smartThreadSerialPort2Read.Priority = ThreadPriority.Normal;
this.smartThreadSerialPort2Read.Start();
//this.smartThreadSerialPort2OverRun.Start();
#region Communication
if (this.SystemConfig1.SerialCOM1Mode != (int)Define.E_CommMode.f0_None)
@ -12399,6 +12657,60 @@ namespace ITC81DB_0H.Forms
#endregion
#region Event Handler
private void SerialReceiveData(string data)
{
string cmd = "", dataID = "", transferCNT = "", lane = "";
try
{
if (this.FlagSerialDll == false)
{
cmd = data.Substring(0, 3);
if (cmd == "SR0")
{
if (this.SizeCheck("S", data) == true && this.ChksumCheck(data) == true)
{
dataID = data.Substring(3, 1);
transferCNT = data.Substring(4, 1);
lane = data.Substring(5, 1);
this.TransferDataRespone(CommunicationCommand.StartDataCMD, lane, dataID, transferCNT, ((int)Define.E_ResponseData.ACK).ToString());
Application.DoEvents();
}
}
}
// 수신 버퍼 삭제 하고 테스트
this.QueueCommunicationRecive.Enqueue(data);
//this.ReceiveData1(data);
this.ChildFormMainDisplay.labelBufferCNT.BeginInvoke(new Action(() =>
{
this.ChildFormMainDisplay.labelBufferCNT.Text = this.QueueCommunicationRecive.Count.ToString();
}));
// 통신 확인
if (this.CommunicationCheckCount / 3 == 1)
{
if (this.ChildFormMainDisplay != null)
this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = true;
this.CommunicationCheckCount = 0;
}
else
{
if (this.ChildFormMainDisplay != null)
this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = false;
this.CommunicationCheckCount += 1;
}
}
catch
{
}
}
private void smartSerialPort1_OnReadQueueEvent()
{
int ret = 0;
@ -12696,19 +13008,25 @@ namespace ITC81DB_0H.Forms
}
private void smartSerialPort2_OnReadQueueEvent()
{
this.ReceiveData();
string strTemp = "";
byte[] readByte;
// 통신 확인
if (this.CommunicationCheckCount / 3 == 1)
SmartSerialPort.FRAMEDATAREADSTATUS receiveDataState = SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY;
try
{
this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = true;
this.CommunicationCheckCount = 0;
receiveDataState = this.smartSerialPort2.ReadQueue(out readByte);
strTemp = Encoding.Default.GetString(readByte, 0, readByte.Length);
}
else
catch
{
this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = false;
this.CommunicationCheckCount += 1;
return;
}
if ((receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY) || (receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.FAILDATA))
return;
this.SerialReceiveData(strTemp);
}
private void smartSerialPort3_OnReadQueueEvent()
{
@ -13926,6 +14244,29 @@ namespace ITC81DB_0H.Forms
this.SetTrackingHistoryData(alarm, status);
}
private void smartThreadSerialPort2Read_UIThreadFunction(ThreadArgs args)
{
if (this.QueueCommunicationRecive.Count != 0)
{
this.ReceiveData(this.QueueCommunicationRecive.Dequeue());
this.ChildFormMainDisplay.labelBufferCNT.BeginInvoke(new Action(() =>
{
this.ChildFormMainDisplay.labelBufferCNT.Text = this.QueueCommunicationRecive.Count.ToString();
}));
}
}
private void smartSerialSerialPort2_OnPortError(System.IO.Ports.SerialError eErrorState)
{
this.IndexOverRun++;
this.QueueOverRun.Enqueue(string.Format("{0}", this.IndexOverRun));
}
private void smartThreadSerialPort2OverRun_UIThreadFunction(ThreadArgs args)
{
if (this.QueueOverRun.Count != 0)
this.ChildFormMainDisplay.UpdateDisplayOverRun(this.QueueOverRun.Dequeue());
}
#region UserManagerEvent
private void UserManager_UserListLogoutDataEvent(int status)
{

View File

@ -165,6 +165,12 @@
<metadata name="timerUserList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>710, 57</value>
</metadata>
<metadata name="smartThreadSerialPort2OverRun.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>34, 95</value>
</metadata>
<metadata name="smartThreadSerialPort2Read.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>264, 95</value>
</metadata>
<metadata name="$this.FormFactorShadowProperty" xml:space="preserve">
<value>WEBPAD</value>
</metadata>
@ -172,6 +178,6 @@
<value>False</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>92</value>
<value>118</value>
</metadata>
</root>

View File

@ -66,6 +66,9 @@
this.labelUserID = new SmartX.SmartLabel();
this.labelUserLevel = new SmartX.SmartLabel();
this.labelAlarmWindow = new SmartX.SmartLabel();
this.labelMissingCount = new SmartX.SmartLabel();
this.labelBufferCNT = new SmartX.SmartLabel();
this.labelOverrun = new SmartX.SmartLabel();
((System.ComponentModel.ISupportInitialize)(this.smartForm1)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
@ -118,7 +121,7 @@
//
// buttonExit
//
this.buttonExit.Location = new System.Drawing.Point(327, 0);
this.buttonExit.Location = new System.Drawing.Point(726, 457);
this.buttonExit.Name = "buttonExit";
this.buttonExit.Size = new System.Drawing.Size(56, 20);
this.buttonExit.TabIndex = 4;
@ -666,18 +669,19 @@
this.labelBarcode.ForeColor = System.Drawing.Color.White;
this.labelBarcode.InitVisible = true;
this.labelBarcode.LineSpacing = 0F;
this.labelBarcode.Location = new System.Drawing.Point(389, 0);
this.labelBarcode.Location = new System.Drawing.Point(79, 26);
this.labelBarcode.Name = "labelBarcode";
this.labelBarcode.Size = new System.Drawing.Size(132, 20);
this.labelBarcode.Size = new System.Drawing.Size(286, 30);
this.labelBarcode.TabIndex = 547;
this.labelBarcode.Text = "2234567890";
this.labelBarcode.TextHAlign = SmartX.SmartLabel.TextHorAlign.Left;
this.labelBarcode.TextVAlign = SmartX.SmartLabel.TextVerAlign.Top;
this.labelBarcode.TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;
this.labelBarcode.Visible = false;
this.labelBarcode.Wordwrap = false;
//
// buttonMemory
//
this.buttonMemory.Location = new System.Drawing.Point(265, 0);
this.buttonMemory.Location = new System.Drawing.Point(726, 431);
this.buttonMemory.Name = "buttonMemory";
this.buttonMemory.Size = new System.Drawing.Size(56, 20);
this.buttonMemory.TabIndex = 547;
@ -864,12 +868,78 @@
this.labelAlarmWindow.Wordwrap = false;
this.labelAlarmWindow.Click += new System.EventHandler(this.labelAlarmWindow_Click);
//
// labelMissingCount
//
this.labelMissingCount.BackColor = System.Drawing.Color.Silver;
this.labelMissingCount.BackPictureBox = this.smartForm1;
this.labelMissingCount.BackPictureBox1 = null;
this.labelMissingCount.BackPictureBox2 = null;
this.labelMissingCount.BorderColor = System.Drawing.Color.Black;
this.labelMissingCount.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.labelMissingCount.ForeColor = System.Drawing.Color.Silver;
this.labelMissingCount.InitVisible = true;
this.labelMissingCount.LineSpacing = 0F;
this.labelMissingCount.Location = new System.Drawing.Point(471, 0);
this.labelMissingCount.Name = "labelMissingCount";
this.labelMissingCount.Size = new System.Drawing.Size(50, 20);
this.labelMissingCount.TabIndex = 605;
this.labelMissingCount.Text = "0";
this.labelMissingCount.TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle;
this.labelMissingCount.TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;
this.labelMissingCount.Visible = false;
this.labelMissingCount.Wordwrap = false;
//
// labelBufferCNT
//
this.labelBufferCNT.BackColor = System.Drawing.Color.Silver;
this.labelBufferCNT.BackPictureBox = this.smartForm1;
this.labelBufferCNT.BackPictureBox1 = null;
this.labelBufferCNT.BackPictureBox2 = null;
this.labelBufferCNT.BorderColor = System.Drawing.Color.Black;
this.labelBufferCNT.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.labelBufferCNT.ForeColor = System.Drawing.Color.Silver;
this.labelBufferCNT.InitVisible = true;
this.labelBufferCNT.LineSpacing = 0F;
this.labelBufferCNT.Location = new System.Drawing.Point(415, 0);
this.labelBufferCNT.Name = "labelBufferCNT";
this.labelBufferCNT.Size = new System.Drawing.Size(50, 20);
this.labelBufferCNT.TabIndex = 604;
this.labelBufferCNT.Text = "0";
this.labelBufferCNT.TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle;
this.labelBufferCNT.TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;
this.labelBufferCNT.Visible = false;
this.labelBufferCNT.Wordwrap = false;
//
// labelOverrun
//
this.labelOverrun.BackColor = System.Drawing.Color.Silver;
this.labelOverrun.BackPictureBox = this.smartForm1;
this.labelOverrun.BackPictureBox1 = null;
this.labelOverrun.BackPictureBox2 = null;
this.labelOverrun.BorderColor = System.Drawing.Color.Black;
this.labelOverrun.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.labelOverrun.ForeColor = System.Drawing.Color.Silver;
this.labelOverrun.InitVisible = true;
this.labelOverrun.LineSpacing = 0F;
this.labelOverrun.Location = new System.Drawing.Point(359, 0);
this.labelOverrun.Name = "labelOverrun";
this.labelOverrun.Size = new System.Drawing.Size(50, 20);
this.labelOverrun.TabIndex = 603;
this.labelOverrun.Text = "0";
this.labelOverrun.TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle;
this.labelOverrun.TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;
this.labelOverrun.Visible = false;
this.labelOverrun.Wordwrap = false;
//
// FormMainDisplay
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(800, 600);
this.Controls.Add(this.labelMissingCount);
this.Controls.Add(this.labelBufferCNT);
this.Controls.Add(this.labelOverrun);
this.Controls.Add(this.labelAlarmWindow);
this.Controls.Add(this.labelExpireOfPassword);
this.Controls.Add(this.labelUserID);
@ -942,5 +1012,8 @@
private SmartX.SmartLabel labelUserID;
private SmartX.SmartLabel labelUserLevel;
private SmartX.SmartLabel labelAlarmWindow;
public SmartX.SmartLabel labelMissingCount;
public SmartX.SmartLabel labelBufferCNT;
public SmartX.SmartLabel labelOverrun;
}
}

View File

@ -248,12 +248,32 @@ namespace ITC81DB_0H.Forms
{
if (visible == false)
{
if (this.ParentForm.SystemConfig2.Barcode != 0)
this.labelBarcode.Visible = false;
//this.labelComRetry.Visible = false;
//this.labelComRetry3th.Visible = false;
this.labelOverrun.Visible = false;
this.labelBufferCNT.Visible = false;
this.labelMissingCount.Visible = false;
//this.labelBARCD.Visible = false;
}
else
{
if (this.ParentForm.SystemConfig2.Barcode != 0)
{
this.labelBarcode.Text = "";
this.labelBarcode.Visible = true;
}
//this.labelComRetry.Visible = true;
//this.labelComRetry3th.Visible = true;
this.labelOverrun.Visible = true;
this.labelBufferCNT.Visible = true;
this.labelMissingCount.Visible = true;
//this.labelBARCD.Text = "";
//this.labelBARCD.Visible = true;
}
}
public void BottomButtonLocation(int buttonNo, SmartX.SmartButton button)
@ -386,6 +406,7 @@ namespace ITC81DB_0H.Forms
}
public void Clear()
{
this.ParentForm.MissingCommIDCount = 0;
this.ParentForm.ClearQueue();
this.ClearCurrentData();
@ -1018,6 +1039,12 @@ namespace ITC81DB_0H.Forms
{
UserManager.UserManager_AutoLogoutTimeoutReset();
}
public void UpdateDisplayOverRun(string value)
{
this.labelOverrun.Text = value;
}
private bool UI_Invoke(ThreadStart invoker)
{
try
@ -1802,11 +1829,8 @@ namespace ITC81DB_0H.Forms
if (this.ParentForm.SystemConfig3.IsPart11 == true)
this.Part11AutomaticLogoutReset();
if (this.ParentForm.SystemConfig1.IsLogin == false)
{
this.ParentForm.ChildFormMenu.DisplayHiddenMenu(this.ParentForm.CurrentSystemStatus.CurrentDisplay, this.ParentForm.SystemConfig1);
}
}
private void buttonMenu_Click(object sender, EventArgs e)
{
// Automatic Logout Reset
@ -1908,7 +1932,7 @@ namespace ITC81DB_0H.Forms
private void buttonExit_Click(object sender, EventArgs e)
{
this.ParentForm.CloseSmartUartLink();
this.ParentForm.CloseSmartSerialPort2();
this.ParentForm.smartFileCommunicationLog.Close();
this.ParentForm.smartFileCheckLog.Close();
this.ParentForm.Close();

File diff suppressed because it is too large Load Diff

View File

@ -779,6 +779,9 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="SerialManager\SerialManager.cs" />
<Compile Include="SerialManager\SerialManager.Define.cs" />
<Compile Include="SerialManager\SerialManager.Structure.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Version.txt" />

View File

@ -0,0 +1,69 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ITC81DB_0H.SerialManager
{
public partial class SerialMgrComm
{
private const string PathDll = "SD Card\\Run\\DllSerialMgr.dll";
public delegate void fnSerialVersionCB(StringBuilder pVersion);
public static fnSerialVersionCB fnSerialVersionCallback;
public delegate void fnSerialMgrDebugCB(int level, StringBuilder pMessage);
public static fnSerialMgrDebugCB fnSerialMgrDebugCallback;
public delegate void fnSerialMgrPortConnectCB(StringBuilder commPort, int status, int errDetail);
public static fnSerialMgrPortConnectCB fnSerialMgrPortConnectCallback;
public delegate void fnSerialMgrRcvPacketCB(StringBuilder commPort, IntPtr pData, int length);
public static fnSerialMgrRcvPacketCB fnSerialMgrRcvPacketCallback;
public delegate void fnSerialMgrRcvErrPacketCB(StringBuilder commPort, IntPtr pData, int length);
public static fnSerialMgrRcvErrPacketCB fnSerialMgrRcvErrPacketCallback;
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern void DLL_SerialMgr_Register_DebugCB(fnSerialMgrDebugCB func);
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern void DLL_SerialMgr_Register_ConnectCB(fnSerialMgrPortConnectCB func);
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern void DLL_SerialMgr_Register_VersionCB(fnSerialVersionCB func);
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern void DLL_SerialMgr_Register_RcvPacketCB(fnSerialMgrRcvPacketCB func);
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern void DLL_SerialMgr_Register_RcvErrPacketCB(fnSerialMgrRcvErrPacketCB func);
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern void DLL_SerialMgr_HelloWorld();
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern void DLL_SerialMgr_Getversion();
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern void DLL_SerialMgr_Activation();
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern void DLL_SerialMgr_Deactivation();
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern int DLL_SerialMgr_PortOpen(IntPtr commPort, int BaudRate, int StopBit, int Parity, int DataBit);
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern int DLL_SerialMgr_PortClose(IntPtr commPort);
[DllImport(PathDll, CallingConvention = CallingConvention.Winapi)]
public static extern int DLL_SerialMgr_PortSendMsg(IntPtr commPort, IntPtr pData, int Length);
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace ITC81DB_0H.SerialManager
{
public partial class SerialMgrComm
{
//fnSerialMgrDebugCB
public const int SERIALMGR_DBG_NORMAL = 0x0001;
public const int SERIALMGR_DBG_THREAD = 0x0002;
public const int SERIALMGR_DBG_LIST = 0x0004;
public const int SERIALMGR_DBG_PORT = 0x0008;
// fnSerialMgrConnectCB : status
public const int SERIAL_STATUS_DISCONNECT = 0x00;
public const int SERIAL_STATUS_CONNECT = 0x01;
public const int SERIAL_STATUS_ERROR = 0x02;
public const int MAX_COMMPORT_SIZE = 10;
// fnSerialMgrConnectCB : errDetail
public enum serial_error_detail_e
{
SERIAL_ERR_NONE = 0x00,
SERIAL_ERR_CREATE,
SERIAL_ERR_PARAMETER,
SERIAL_ERR_TIMEOUT,
SERIAL_ERR_WRITE,
SERIAL_ERR_READ,
SERIAL_ERR_MAX
};
}
}

View File

@ -0,0 +1,274 @@
#define CONSOLE_DBUGGING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Collections;
namespace ITC81DB_0H.SerialManager
{
public partial class SerialMgrComm
{
public delegate void ObjectEventHandler(object data);
public static event ObjectEventHandler SerialPortMessageReceive;
public static event ObjectEventHandler SerialPortErrMessageReceive;
public static void IntializeSerialManager()
{
//Console.Write("Initialize Serial Manager \n");
// Register Callback
fnSerialMgrDebugCallback = serialDebugCallback;
DLL_SerialMgr_Register_DebugCB(fnSerialMgrDebugCallback);
fnSerialMgrPortConnectCallback = serialPortConnectCallback;
DLL_SerialMgr_Register_ConnectCB(fnSerialMgrPortConnectCallback);
fnSerialVersionCallback = serialVersionCallback;
DLL_SerialMgr_Register_VersionCB(fnSerialVersionCallback);
fnSerialMgrRcvPacketCallback = serialRcvPacketMsgCallback;
DLL_SerialMgr_Register_RcvPacketCB(fnSerialMgrRcvPacketCallback);
fnSerialMgrRcvErrPacketCallback = serialRcvErrPacketMsgCallback;
DLL_SerialMgr_Register_RcvErrPacketCB(fnSerialMgrRcvErrPacketCallback);
// test
//DLL_SerialMgr_HelloWorld();
// get the lib version
DLL_SerialMgr_Getversion();
// activate the dll thread
DLL_SerialMgr_Activation();
}
#region DLL_CALLBACK
private static void serialVersionCallback(StringBuilder versionInfo)
{
try
{
//Console.Write("\n-------------------------------\n");
//Console.Write("lib version = " + versionInfo + "\n");
//Console.Write("-------------------------------\n");
}
catch (Exception e)
{
throw (e);
}
}
private static void serialPortConnectCallback(StringBuilder commPort, int status, int errDetail)
{
try
{
//Console.Write(commPort + ": status = " + status.ToString() +" , detail = " + errDetail.ToString() + "\n");
}
catch (Exception e)
{
throw (e);
}
}
private static void serialDebugCallback(int type, StringBuilder pMessage)
{
try
{
//Console.Write(pMessage);
}
catch (Exception e)
{
throw (e);
}
}
// https://stackoverflow.com/questions/22938756/how-to-marshal-c-array-to-c-sharp-via-intptr
public static void serialRcvPacketMsgCallback(StringBuilder commPort, IntPtr pData, int length)
{
try
{
if (commPort.Length == 0)
return;
if ( (pData == IntPtr.Zero) || (length == 0) )
return;
byte[] data = new byte[length];
Marshal.Copy(pData, data, 0, (int)length);
string sdata = Encoding.Default.GetString(data, 0, data.Length);
if (SerialPortMessageReceive != null)
SerialPortMessageReceive(sdata);
#if TEST_CB
String commPortStr = commPort.ToString();
serialPortMessageByte(commPortStr, data, length);
#endif
//Console.Write("comm port : " + commPort + ", length = " + length.ToString() + "\n");
#if TEST_DEBUG
// https://stackoverflow.com/questions/1342922/console-writeline-as-hexadecimal
int index = 0;
foreach (byte temp in data)
{
Console.Write(temp.ToString("X2") + " ");
index++;
if (index % 16 == 0) Console.Write("\n");
}
Console.Write("\n");
#endif
//data = null;
//GC.Collect();
//GC.WaitForPendingFinalizers();
}
catch (Exception e)
{
throw (e);
}
}
public static void serialRcvErrPacketMsgCallback(StringBuilder commPort, IntPtr pData, int length)
{
try
{
if (commPort.Length == 0)
return;
if ((pData == IntPtr.Zero) || (length == 0))
return;
byte[] data = new byte[length];
Marshal.Copy(pData, data, 0, (int)length);
string sdata = Encoding.Default.GetString(data, 0, data.Length);
if (SerialPortErrMessageReceive != null)
SerialPortErrMessageReceive(sdata);
//String commPortStr = commPort.ToString();
//serialPortMessageByte(commPortStr, data, length);
//Console.Write("Err : comm port : " + commPort + ", length = " + length.ToString() + "\n");
#if (TEST_DEBUG1)
// https://stackoverflow.com/questions/1342922/console-writeline-as-hexadecimal
int index = 0;
foreach (byte temp in data)
{
Console.Write(temp.ToString("X2") + " ");
index++;
if (index == 5) break;
if (index % 16 == 0) Console.Write("\n");
}
Console.Write("\n");
#endif
// https://dhshin94.tistory.com/135
//data = null;
//GC.Collect();
//GC.WaitForPendingFinalizers();
}
catch (Exception e)
{
throw (e);
}
}
#endregion // DLL_CALLBACK
#region DLL_COMMAND
public static void serialPortOpen(String commPort, int BaudRate, int stopBit, int parity, int dataBit)
{
IntPtr pCommPort = Marshal.StringToBSTR(commPort.ToString());
DLL_SerialMgr_PortOpen(pCommPort, BaudRate, stopBit, parity, dataBit);
}
public static void serialPortClose(String commPort)
{
IntPtr pCommPort = Marshal.StringToBSTR(commPort.ToString());
DLL_SerialMgr_PortClose(pCommPort);
}
public static void serialPortMessageByte(String commport, byte[] data, int length)
{
IntPtr pCommPort = Marshal.StringToBSTR(commport.ToString());
IntPtr ptr = Marshal.AllocHGlobal(length);
Marshal.Copy(data, 0, ptr, length);
DLL_SerialMgr_PortSendMsg(pCommPort, ptr, length);
//string sdata = Encoding.Default.GetString(data, 0, data.Length);
Marshal.FreeHGlobal(ptr);
// if (SerialPortMessageReceive != null)
// SerialPortMessageReceive(sdata);
}
//https://stackoverflow.com/questions/13418795/convert-byte-array-to-structure-in-the-compact-framework
public static void serialPortMessage(String commPort, String Message)
{
IntPtr pCommPort = Marshal.StringToBSTR(commPort.ToString());
StringBuilder sb = new StringBuilder();
sb.Append((char)0x02);
sb.Append(Message);
sb.Append((char)0x03);
Message = sb.ToString();
byte[] buffer = Encoding.ASCII.GetBytes(Message);
int count = Encoding.ASCII.GetByteCount(Message);
//byte[] buffer = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//int count = 10;
IntPtr ptr = Marshal.AllocHGlobal(count);
Marshal.Copy(buffer, 0, ptr, count);
DLL_SerialMgr_PortSendMsg(pCommPort, ptr, count);
Marshal.FreeHGlobal(ptr);
}
public static void serialPortMessageRaw(String commPort, String Message)
{
IntPtr pCommPort = Marshal.StringToBSTR(commPort.ToString());
byte[] buffer = Encoding.ASCII.GetBytes(Message);
int count = Encoding.ASCII.GetByteCount(Message);
//byte[] buffer = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//int count = 10;
IntPtr ptr = Marshal.AllocHGlobal(count);
Marshal.Copy(buffer, 0, ptr, count);
DLL_SerialMgr_PortSendMsg(pCommPort, ptr, count);
Marshal.FreeHGlobal(ptr);
}
#endregion
}
}

View File

@ -12,6 +12,11 @@
기본형 컨베어 고정밀센서 계량기
*/
@ Ver 3.2.0 by CJY
- 2023.11.08
- Ver 3.1.2 Modify
- 재전송 기능 추가
@ Ver 3.1.2 by CJY
- 2023.10.31
- Ver 3.1.1 Modify

Binary file not shown.