public int GetProcessStatusTable(ref DataTable dta) { int iReturnCode = 9; //Return code string szAdd = "ZR"; int iNumberOfData = 94; //Data for 'DeviceSize' short[] arrDeviceValue = new short[iNumberOfData]; List <ConvResultTableData> convtables = new List <ConvResultTableData>(); try { if (Connected == true) { //List<JobCode> jobcode = new List<JobCode>(); for (int id = 1; id <= 400; id++) { Debug.WriteLine("Ambil data untuk ind = " + id); int iStartAddr = ((id - 1) * 100) + 11000; string szDeviceName = szAdd + iStartAddr.ToString(); iReturnCode = plc.ReadDeviceBlock2(szDeviceName, iNumberOfData, out arrDeviceValue[0]); if (iReturnCode == 0) { //int k = 0; string szPID = ""; string szVIN = ""; string szSuffix = ""; string szModelCode = ""; string szWLCCode = ""; string szChassisNo = ""; short[] arrJob = new short[60]; int idxJob = 0; short idx = 0; Debug.WriteLine("Start Baca PLC"); Debug.WriteLine("Jumlah yang akan dibace" + arrDeviceValue.Length); for (int k = 0; k < arrDeviceValue.Length; k++) { short baca = arrDeviceValue[k]; //if (k < 95) //{ // if (k == 0) { idx = baca; } else if (Enumerable.Range(1, 5).Contains(k)) { byte[] kon = BitConverter.GetBytes(baca); foreach (byte m in kon) { char tchar = Convert.ToChar(m); szPID += tchar.ToString(); } } else if (Enumerable.Range(6, 9).Contains(k)) { byte[] kon = BitConverter.GetBytes(baca); foreach (byte m in kon) { char tchar = Convert.ToChar(m); szVIN += tchar.ToString(); } } else if (k == 15) { byte[] kon = BitConverter.GetBytes(baca); foreach (byte m in kon) { char tchar = Convert.ToChar(m); szSuffix += tchar.ToString(); } } else if (Enumerable.Range(16, 2).Contains(k)) { byte[] kon = BitConverter.GetBytes(baca); foreach (byte m in kon) { char tchar = Convert.ToChar(m); szModelCode += tchar.ToString(); } } else if (Enumerable.Range(18, 2).Contains(k)) { byte[] kon = BitConverter.GetBytes(baca); foreach (byte m in kon) { char tchar = Convert.ToChar(m); szWLCCode += tchar.ToString(); } } else if (Enumerable.Range(20, 10).Contains(k)) { byte[] kon = BitConverter.GetBytes(baca); foreach (byte m in kon) { char tchar = Convert.ToChar(m); szChassisNo += tchar.ToString(); } } else if (Enumerable.Range(35, 60).Contains(k)) { arrJob[idxJob] = baca; idxJob++; } //} //k++; } //Debug.WriteLine("Data satu row = " + k.ToString()); //creat job list List <JobCode> jobCodes = new List <JobCode>(); for (int ijob = 0; ijob < 30; ijob++) { Debug.WriteLine("Add Job Code idx = " + ijob.ToString() + "; Jumlahtotal job = " + arrJob.Length.ToString()); JobCode jobCode = new JobCode { B1 = arrJob[(ijob * 2)], B2 = arrJob[(ijob * 2) + 1] }; jobCodes.Add(jobCode); } //insert to datatable convtables.Add(new ConvResultTableData { Id = idx, pid = szPID, vin = szVIN, suffix = szSuffix, model_code = szModelCode, wlc_code = szWLCCode, chassis_number = szChassisNo, jobCode = jobCodes }); } else { iReturnCode = 8; } } } else { iReturnCode = 7; } //ListtoDataTable lsttodt = new ListtoDataTable(); dta = ListtoDataTable.ListToDataTable(convtables); } //Exception processing catch (Exception exception) { Debug.WriteLine(exception.Message); string stringFormat = "Read Conversion Result Table Failed"; StatusPLCLog = stringFormat; iReturnCode = 9; } return(iReturnCode); }
public void GetProcessTable(ref DataTable dta) { int iReturnCode; //Return code int iStartAddr; int iStart; string szAdd = "ZR"; string szDeviceName; //List data for 'DeviceName' int iNumberOfData = 32; //Data for 'DeviceSize' short[] arrDeviceValue = new short[iNumberOfData]; int iProcessType = 0; int iProcessDepth = 0; int iNormalReverse = 0; int iReverseWidth = 0; int iMarginofAdvance = 0; int iMarginofDelay = 0; int iCutOff = 0; string szProcessName = ""; List <ProcessTableData> processtables = new List <ProcessTableData>(); //DataTable dta = new DataTable(); try { int idx = 0; for (int cclink = 1; cclink <= 4; cclink++) { iStart = ((cclink - 1) * 1000) + 3000; for (int stno = 1; stno <= 30; stno++) { iStartAddr = ((stno - 1) * 32) + iStart; szDeviceName = szAdd + iStartAddr.ToString(); iReturnCode = 0; if (Connected == true) { iReturnCode = plc.ReadDeviceBlock2(szDeviceName, iNumberOfData, out arrDeviceValue[0]); } if (iReturnCode == 0) { int k = 0; szProcessName = ""; foreach (var baca in arrDeviceValue) { if (k < 16) { switch (k) { case 0: iProcessType = baca; break; case 1: iProcessDepth = baca; break; case 2: iNormalReverse = baca; break; case 3: iReverseWidth = baca; break; case 4: iMarginofAdvance = baca; break; case 5: iMarginofDelay = baca; break; case 6: iCutOff = baca; break; default: break; } } else { byte[] kon = BitConverter.GetBytes(baca); foreach (byte m in kon) { char tchar = Convert.ToChar(m); szProcessName += tchar.ToString(); } } k++; } //insert to datatable processtables.Add(new ProcessTableData { id = idx, cc_link_no = cclink, stno = stno, process_type = iProcessType, depth = iProcessDepth, normal_reverse = iNormalReverse, margin_reverse = iReverseWidth, margin_of_adv = iMarginofAdvance, margin_of_delay = iMarginofDelay, cut_off = iCutOff, process_name = szProcessName }); } idx++; } } //ListtoDataTable lsttodt = new ListtoDataTable(); dta = ListtoDataTable.ListToDataTable(processtables); } //Exception processing catch (Exception exception) { Debug.WriteLine(exception.Message); string stringFormat = "Read Process Table Failed"; StatusPLCLog = stringFormat; } //return dta; }