- 재전송기능 추가 - Serial Dll 사용(SerialManager)

현 버전에서는 재전송기능 사용은 하지 않고, 두번째 전송되는 판정데이터만 무시
 - (버그수정)단순 로그인 기능 사용 시, admin 비번 변경하면 Level1로 변하는 버그 수정
 - I/O Test
   확장 I/O 보드 테스트 부분 추가(출력 17~32)
 - 임펠러 회전각도 360도 추가
   설정 시, 180 + 180 two step으로 회전
master
DESKTOP-999R8N3\CJY 2024-11-20 09:40:55 +09:00
parent 7b277d0ff9
commit e7c1122b14
13 changed files with 1261 additions and 113 deletions

View File

@ -115,10 +115,10 @@
//
// listBoxDataList
//
this.listBoxDataList.Font = new System.Drawing.Font("Arial", 15F, System.Drawing.FontStyle.Bold);
this.listBoxDataList.Font = new System.Drawing.Font("Arial", 14F, System.Drawing.FontStyle.Bold);
this.listBoxDataList.Location = new System.Drawing.Point(407, 188);
this.listBoxDataList.Name = "listBoxDataList";
this.listBoxDataList.Size = new System.Drawing.Size(355, 278);
this.listBoxDataList.Size = new System.Drawing.Size(355, 296);
this.listBoxDataList.TabIndex = 137;
//
// labelFileCount

File diff suppressed because it is too large Load Diff

View File

@ -85,7 +85,7 @@ namespace INT69DB_2A.Forms
this.buttonInputRead.ButtonUp();
this.timer.Enabled = false;
this.groupBoxPLC.Location = new Point(50, 105);
this.groupBoxPLC.Location = new Point(16, 108);
this.groupBoxPLC.Visible = false;
}
private void DefaultSetting()
@ -149,12 +149,28 @@ namespace INT69DB_2A.Forms
this.CollectionOutputButton.Add(this.buttonOutput14);
this.CollectionOutputButton.Add(this.buttonOutput15);
this.CollectionOutputButton.Add(this.buttonOutput16);
this.CollectionOutputButton.Add(this.buttonOutput17);
this.CollectionOutputButton.Add(this.buttonOutput18);
this.CollectionOutputButton.Add(this.buttonOutput19);
this.CollectionOutputButton.Add(this.buttonOutput20);
this.CollectionOutputButton.Add(this.buttonOutput21);
this.CollectionOutputButton.Add(this.buttonOutput22);
this.CollectionOutputButton.Add(this.buttonOutput23);
this.CollectionOutputButton.Add(this.buttonOutput24);
this.CollectionOutputButton.Add(this.buttonOutput25);
this.CollectionOutputButton.Add(this.buttonOutput26);
this.CollectionOutputButton.Add(this.buttonOutput27);
this.CollectionOutputButton.Add(this.buttonOutput28);
this.CollectionOutputButton.Add(this.buttonOutput29);
this.CollectionOutputButton.Add(this.buttonOutput30);
this.CollectionOutputButton.Add(this.buttonOutput31);
this.CollectionOutputButton.Add(this.buttonOutput32);
for (int i = 0; i < this.CollectionInputLabelName.Count; i++)
{
this.CollectionInputLabelName[i].Text = string.Format("IN{0}", i + 1);
for (int i = 0; i < this.CollectionOutputButton.Count; i++)
this.CollectionOutputButton[i].Text = string.Format("OUT{0}", i + 1);
}
//if (this.ParentForm.SystemConfig.EquipmentMode == 0)
//{

View File

@ -107,7 +107,7 @@ namespace INT69DB_2A.Forms
}
private void DefaultSetting()
{
this.labelDisplayVer.Text = "5.2.1";
this.labelDisplayVer.Text = "5.3.0";
this.labelUserMgerVer.Text = "";
this.labelAes128Ver.Text = "";
this.labelSerialNo.Text = this.ParentForm.SystemConfig.SerialNumber;

View File

@ -17,6 +17,7 @@ using INT69DB_2A.DialogForms;
using INT69DB_2A_ImageDll;
using INT69DB_2A.Part11_Encryption;
using INT69DB_2A.Part11_UserManager;
using INT69DB_2A.SerialManger;
namespace INT69DB_2A.Forms
{
@ -40,6 +41,9 @@ namespace INT69DB_2A.Forms
private bool IsTimerWaitResponseEnableTrue;
public int FlagAutomaticLogoutWarningTime; //Part11 Auto Logout
public bool IsLogProcessing;
public string ComPortMainToLCD; // DllSerial Port
public bool FlagSerialDll = false;
private string TransferNum;
// Motor Download 통신용 변수
public int LineNum;
@ -437,6 +441,7 @@ namespace INT69DB_2A.Forms
this.ColorLogOff = Color.Red;
this.ColorLogOn = Color.Yellow;
this.IsLogProcessing = false;
this.TransferNum = "-";
this.PathLaunchFolder = "SD Card\\";
this.PathSystemFileFolder1 = this.PathLaunchFolder + "SystemFile1\\";
@ -545,7 +550,60 @@ namespace INT69DB_2A.Forms
this.EthernetClientDisconnect();
this.CurrentAlarmTotalPassCnt = new Counter(this.SystemConfig.EquipmentColumns, this.SystemConfig.AlarmTotalPassCnt);
if (this.FlagSerialDll == true)
{
// SerialDll Initialize
this.ComPortMainToLCD = "COM2:";
SerialMgrComm.IntializeSerialManager();
SerialMgrComm.SerialPortErrMessageReceive += this.SerialPort_MessageReceive;
SerialMgrComm.SerialPortErrMessageReceive += this.SerialPort_ErrMessageReceive;
}
}
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());
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1})", DateTime.Now, 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));
});
}
private void InitializeUserManager()
{
UserManager.UserListNewDataEvent += this.UserManager_UserListNewDataEvent;
@ -578,31 +636,6 @@ namespace INT69DB_2A.Forms
Encryption.InitializeEncryption();
}
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 TrasferSystemParameter(SystemConfigurationItem item)
{
@ -3585,15 +3618,24 @@ namespace INT69DB_2A.Forms
try
{
if (this.smartSerialPortLink.IsOpen == false)
this.smartSerialPortLink.Open();
if (this.FlagSerialDll == false)
{
if (this.smartSerialPortLink.IsOpen == false)
this.smartSerialPortLink.Open();
}
else
{
// Port : COM2
// Baudrate : 115200
SerialMgrComm.serialPortOpen(this.ComPortMainToLCD, 115200, 0, 0, 8);
}
}
catch
{
}
#region Test 용 통신 로그
fullPath = this.PathDataBackupFolder + "Communicationlog.txt";
fullPath = this.PathDataBackupFolder + "INT69DB_2A_Communicationlog.txt";
this.smartFileCommunicationLog.FilePathName = fullPath;
//this.smartFileCommunicationLog.Open();
//this.IsCommunicationLogOpen = true;
@ -3606,7 +3648,10 @@ namespace INT69DB_2A.Forms
}
public void CloseSmartUartLink()
{
this.smartSerialPortLink.Close();
if (this.FlagSerialDll == false)
this.smartSerialPortLink.Close();
else
SerialMgrComm.serialPortClose(this.ComPortMainToLCD);
}
private bool SizeCheck(string cmd, string strTemp)
@ -3812,8 +3857,13 @@ namespace INT69DB_2A.Forms
sb.Append(chkSum);
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
if (this.FlagSerialDll == false)
{
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
}
else
SerialMgrComm.serialPortMessage(this.ComPortMainToLCD, sb.ToString());
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
@ -3886,9 +3936,14 @@ namespace INT69DB_2A.Forms
byteData = new byte[byteCollection.Count];
for (int i = 0; i < byteCollection.Count; i++)
byteData[i] = byteCollection[i];
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(byteData);
if (this.FlagSerialDll == false)
{
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(byteData);
}
else
SerialMgrComm.serialPortMessageByte(this.ComPortMainToLCD, byteData, byteData.Length);
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
@ -3918,9 +3973,14 @@ namespace INT69DB_2A.Forms
chkSum = this.Checksumcalculator(sb.ToString());
sb.Append(chkSum);
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
if (this.FlagSerialDll == false)
{
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
}
else
SerialMgrComm.serialPortMessage(this.ComPortMainToLCD, sb.ToString());
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
@ -3928,6 +3988,9 @@ namespace INT69DB_2A.Forms
return ret;
}
/// <summary>
/// 재전송 기능 미사용 시 사용
/// </summary>
private void ReceiveData()
{
int ret = 0;
@ -3975,6 +4038,39 @@ namespace INT69DB_2A.Forms
{
}
}
/// <summary>
/// 재전송 기능 사용 시 사용
/// </summary>
/// <param name="strTemp">수신 데이터</param>
private void ReceiveData(string strTemp)
{
int ret = 0;
byte[] readByte;
try
{
switch (strTemp[0])
{
case 'C':
if ((ret = this.ReceiveCommandC(strTemp)) != 0)
return;
break;
case 'P':
if ((ret = this.ReceiveCommandP(strTemp)) != 0)
return;
break;
case 'S':
if ((ret = this.ReceiveCommandS(strTemp)) != 0)
return;
break;
default:
break;
}
}
catch
{
}
}
private int ReceiveCommandC(string strTemp)
{
@ -4112,6 +4208,7 @@ namespace INT69DB_2A.Forms
{
int ret = 0;
string cmd = "", lane = "", receiveData = "";
string transferNum = "";
// SIZE 확인
if (this.SizeCheck("S", strTemp) == false)
@ -4134,7 +4231,8 @@ namespace INT69DB_2A.Forms
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.WriteString(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));
cmd = strTemp.Substring(0, 3);
cmd = strTemp.Substring(0, 3);
transferNum = strTemp.Substring(3, 1);
lane = strTemp.Substring(5, 1);
receiveData = strTemp.Substring(10, strTemp.Length - 12);
@ -4145,6 +4243,11 @@ namespace INT69DB_2A.Forms
return ret;
break;
case "SR0":
if (this.TransferNum != transferNum)
this.TransferNum = transferNum;
else
return ret = -1;
if ((ret = this.ReceiveCommandSR0(lane, receiveData)) != 0)
return ret;
break;
@ -8374,6 +8477,22 @@ namespace INT69DB_2A.Forms
this.CommunicationCheckCount += 1;
}
}
private void SerialReceiveData(string data)
{
this.ReceiveData(data);
// 통신 확인
if (this.CommunicationCheckCount / 3 == 1)
{
this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = true;
this.CommunicationCheckCount = 0;
}
else
{
this.ChildFormMainDisplay.pictureBoxCommunicationStatus.Visible = false;
this.CommunicationCheckCount += 1;
}
}
private void timerWaitResponse_Tick(object sender, EventArgs e)
{

View File

@ -126,6 +126,7 @@
this.buttonCom1TestForward = new SmartX.SmartButton();
this.buttonCom1TestReverse = new SmartX.SmartButton();
this.panel1 = new System.Windows.Forms.Panel();
this.radioButtonImpellerMotorAngle360 = new SmartX.SmartRadioButton();
((System.ComponentModel.ISupportInitialize)(this.smartForm1)).BeginInit();
this.groupBoxSelectImpeller.SuspendLayout();
this.groupBoxEach.SuspendLayout();
@ -1023,6 +1024,7 @@
//
this.groupBoxAngle.BackPictureBox = this.smartForm1;
this.groupBoxAngle.BackPictureBox1 = null;
this.groupBoxAngle.Controls.Add(this.radioButtonImpellerMotorAngle360);
this.groupBoxAngle.Controls.Add(this.labelTitleStep2);
this.groupBoxAngle.Controls.Add(this.labelTitleStep1);
this.groupBoxAngle.Controls.Add(this.radioButtonImpellerMotorAngle60);
@ -1104,7 +1106,7 @@
this.radioButtonImpellerMotorAngle60.ImageCheckRadioButton = null;
this.radioButtonImpellerMotorAngle60.ImageUnCheckRadioButton = null;
this.radioButtonImpellerMotorAngle60.InitVisible = true;
this.radioButtonImpellerMotorAngle60.Location = new System.Drawing.Point(102, 42);
this.radioButtonImpellerMotorAngle60.Location = new System.Drawing.Point(102, 37);
this.radioButtonImpellerMotorAngle60.Name = "radioButtonImpellerMotorAngle60";
this.radioButtonImpellerMotorAngle60.OutputOnly = false;
this.radioButtonImpellerMotorAngle60.RadioBackColor = System.Drawing.Color.White;
@ -1130,7 +1132,7 @@
this.radioButtonImpellerMotorAngle180.ImageCheckRadioButton = null;
this.radioButtonImpellerMotorAngle180.ImageUnCheckRadioButton = null;
this.radioButtonImpellerMotorAngle180.InitVisible = true;
this.radioButtonImpellerMotorAngle180.Location = new System.Drawing.Point(360, 42);
this.radioButtonImpellerMotorAngle180.Location = new System.Drawing.Point(102, 69);
this.radioButtonImpellerMotorAngle180.Name = "radioButtonImpellerMotorAngle180";
this.radioButtonImpellerMotorAngle180.OutputOnly = false;
this.radioButtonImpellerMotorAngle180.RadioBackColor = System.Drawing.Color.White;
@ -1156,7 +1158,7 @@
this.radioButtonImpellerMotorAngle120.ImageCheckRadioButton = null;
this.radioButtonImpellerMotorAngle120.ImageUnCheckRadioButton = null;
this.radioButtonImpellerMotorAngle120.InitVisible = true;
this.radioButtonImpellerMotorAngle120.Location = new System.Drawing.Point(274, 42);
this.radioButtonImpellerMotorAngle120.Location = new System.Drawing.Point(274, 37);
this.radioButtonImpellerMotorAngle120.Name = "radioButtonImpellerMotorAngle120";
this.radioButtonImpellerMotorAngle120.OutputOnly = false;
this.radioButtonImpellerMotorAngle120.RadioBackColor = System.Drawing.Color.White;
@ -1182,7 +1184,7 @@
this.radioButtonImpellerMotorAngle90.ImageCheckRadioButton = null;
this.radioButtonImpellerMotorAngle90.ImageUnCheckRadioButton = null;
this.radioButtonImpellerMotorAngle90.InitVisible = true;
this.radioButtonImpellerMotorAngle90.Location = new System.Drawing.Point(188, 42);
this.radioButtonImpellerMotorAngle90.Location = new System.Drawing.Point(188, 37);
this.radioButtonImpellerMotorAngle90.Name = "radioButtonImpellerMotorAngle90";
this.radioButtonImpellerMotorAngle90.OutputOnly = false;
this.radioButtonImpellerMotorAngle90.RadioBackColor = System.Drawing.Color.White;
@ -2512,6 +2514,32 @@
this.panel1.Size = new System.Drawing.Size(800, 348);
this.panel1.Visible = false;
//
// radioButtonImpellerMotorAngle360
//
this.radioButtonImpellerMotorAngle360.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(246)))), ((int)(((byte)(228)))), ((int)(((byte)(180)))));
this.radioButtonImpellerMotorAngle360.BackPictureBox = null;
this.radioButtonImpellerMotorAngle360.BackPictureBox1 = null;
this.radioButtonImpellerMotorAngle360.BackPictureBox2 = null;
this.radioButtonImpellerMotorAngle360.Checked = false;
this.radioButtonImpellerMotorAngle360.Font = new System.Drawing.Font("새굴림", 15F, System.Drawing.FontStyle.Bold);
this.radioButtonImpellerMotorAngle360.GroupID = 0;
this.radioButtonImpellerMotorAngle360.ImageCheckRadioButton = null;
this.radioButtonImpellerMotorAngle360.ImageUnCheckRadioButton = null;
this.radioButtonImpellerMotorAngle360.InitVisible = true;
this.radioButtonImpellerMotorAngle360.Location = new System.Drawing.Point(188, 69);
this.radioButtonImpellerMotorAngle360.Name = "radioButtonImpellerMotorAngle360";
this.radioButtonImpellerMotorAngle360.OutputOnly = false;
this.radioButtonImpellerMotorAngle360.RadioBackColor = System.Drawing.Color.White;
this.radioButtonImpellerMotorAngle360.RadioCheckColor = System.Drawing.Color.Green;
this.radioButtonImpellerMotorAngle360.RadioForeColor = System.Drawing.Color.Black;
this.radioButtonImpellerMotorAngle360.RadioSymbolSize = 14;
this.radioButtonImpellerMotorAngle360.Shadow = false;
this.radioButtonImpellerMotorAngle360.Size = new System.Drawing.Size(80, 26);
this.radioButtonImpellerMotorAngle360.TabIndex = 274;
this.radioButtonImpellerMotorAngle360.Text = "360";
this.radioButtonImpellerMotorAngle360.TextVAlign = SmartX.SmartRadioButton.TextVerAlign.Middle;
this.radioButtonImpellerMotorAngle360.Click += new System.EventHandler(this.radioButtonImpellerMotorAngle_Click);
//
// FormMotorSetting
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@ -2645,5 +2673,6 @@
private SmartX.SmartButton buttonCom1TestForward;
private SmartX.SmartButton buttonCom1TestReverse;
private System.Windows.Forms.Panel panel1;
private SmartX.SmartRadioButton radioButtonImpellerMotorAngle360;
}
}

View File

@ -970,6 +970,7 @@ namespace INT69DB_2A.Forms
this.radioButtonImpellerMotorAngle90.Click -= new EventHandler(this.radioButtonImpellerMotorAngle_Click);
this.radioButtonImpellerMotorAngle120.Click -= new EventHandler(this.radioButtonImpellerMotorAngle_Click);
this.radioButtonImpellerMotorAngle180.Click -= new EventHandler(this.radioButtonImpellerMotorAngle_Click);
this.radioButtonImpellerMotorAngle360.Click -= new EventHandler(this.radioButtonImpellerMotorAngle_Click);
this.comboBoxTwoStepPassAngle.SelectedIndexChanged -= new EventHandler(this.comboBoxTwoStepPassAngle_SelectedIndexChanged);
this.comboBoxTwoStepNGAngle.SelectedIndexChanged -= new EventHandler(this.comboBoxTwoStepNGAngle_SelectedIndexChanged);
@ -992,6 +993,8 @@ namespace INT69DB_2A.Forms
this.radioButtonImpellerMotorAngle90.Checked = true;
else if (this.ParentForm.SystemConfig.ImpellerMotorAnglePass == 3)
this.radioButtonImpellerMotorAngle120.Checked = true;
else if (this.ParentForm.SystemConfig.ImpellerMotorAnglePass == 13)
this.radioButtonImpellerMotorAngle360.Checked = true;
else
{
this.radioButtonImpellerMotorAngle180.Checked = true;
@ -1019,6 +1022,7 @@ namespace INT69DB_2A.Forms
this.radioButtonImpellerMotorAngle90.Click += new EventHandler(this.radioButtonImpellerMotorAngle_Click);
this.radioButtonImpellerMotorAngle120.Click += new EventHandler(this.radioButtonImpellerMotorAngle_Click);
this.radioButtonImpellerMotorAngle180.Click += new EventHandler(this.radioButtonImpellerMotorAngle_Click);
this.radioButtonImpellerMotorAngle360.Click += new EventHandler(this.radioButtonImpellerMotorAngle_Click);
this.comboBoxTwoStepPassAngle.SelectedIndexChanged += new EventHandler(this.comboBoxTwoStepPassAngle_SelectedIndexChanged);
this.comboBoxTwoStepNGAngle.SelectedIndexChanged += new EventHandler(this.comboBoxTwoStepNGAngle_SelectedIndexChanged);
@ -2327,6 +2331,11 @@ namespace INT69DB_2A.Forms
else
this.ParentForm.SystemConfig.ImpellerMotorAngleNG = this.comboBoxTwoStepNGAngle.SelectedIndex + 5;
}
else if (this.radioButtonImpellerMotorAngle360.Checked == true)
{
this.ParentForm.SystemConfig.ImpellerMotorAnglePass = 13;
this.ParentForm.SystemConfig.ImpellerMotorAngleNG = 13;
}
afterAnglePass = this.ReturnAngle(this.ParentForm.SystemConfig.ImpellerMotorAnglePass);
afterAngleNG = this.ReturnAngle(this.ParentForm.SystemConfig.ImpellerMotorAngleNG);

View File

@ -290,8 +290,7 @@ namespace INT69DB_2A.Forms
if (this.SelectedUserItem.Group == DataStore.UserGroup.Admin)
{
if (this.ParentForm.SystemConfig.IsPart11 == true)
item.ActiveLevel = 9;
item.ActiveLevel = 9;
}
else
{

View File

@ -766,6 +766,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,70 @@
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 INT69DB_2A.SerialManger
{
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 INT69DB_2A.SerialManger
{
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,259 @@
#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 INT69DB_2A.SerialManger
{
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);
}
#endregion
}
}

View File

@ -14,6 +14,17 @@
멀티형 2~6열 스틱 계량기
*/
@ Ver 5.3.0 by CJY
- 2024.11.19
- Ver 5.2.1 Modify
- 재전송기능 추가 - Serial Dll 사용(SerialManager)
현 버전에서는 재전송기능 사용은 하지 않고, 두번째 전송되는 판정데이터만 무시
- (버그수정)단순 로그인 기능 사용 시, admin 비번 변경하면 Level1로 변하는 버그 수정
- I/O Test
확장 I/O 보드 테스트 부분 추가(출력 17~32)
- 임펠러 회전각도 360도 추가
설정 시, 180 + 180 two step으로 회전
@ Ver 5.2.1 by CJY
- 2024.08.21
- Ver 5.2.0 Modify