Conceptual principle
|
Physical setup
|
|
|
SCK (PD_SCK): Serial Clock Input
DT (DOUT): Serial Data Output
|
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Net.Http;
using
Windows.ApplicationModel.Background;
using
Windows.Devices.Gpio;
using
Windows.System.Threading;
using
System.Diagnostics;
using
System.Threading.Tasks;
namespace
AlexBackgroundApplication
{
public
sealed
class
StartupTask
: IBackgroundTask
{
BackgroundTaskDeferral deferral;
private
GpioPin pinR, pinG, pinB;
private
GpioPin pinDT, pinSCK;
public
void
Run(IBackgroundTaskInstance taskInstance)
{
deferral = taskInstance.GetDeferral();
InitGPIO();
}
private
void
InitGPIO()
{
DateTime
startTimeDelay =
DateTime
.Now, endTimeDelay;
double
elapsedMillisecsDelay;
int
[] data =
new
int
[3];
double
result = 0;
pinDT = GpioController.GetDefault().OpenPin(23);
pinDT.SetDriveMode(GpioPinDriveMode.Input);
pinSCK = GpioController.GetDefault().OpenPin(18);
pinSCK.SetDriveMode(GpioPinDriveMode.Output);
pinR = GpioController.GetDefault().OpenPin(13);
pinR.SetDriveMode(GpioPinDriveMode.Output);
pinG = GpioController.GetDefault().OpenPin(26);
pinG.SetDriveMode(GpioPinDriveMode.Output);
pinB = GpioController.GetDefault().OpenPin(16);
pinB.SetDriveMode(GpioPinDriveMode.Output);
pinR.Write(GpioPinValue.High);
pinG.Write(GpioPinValue.Low);
pinB.Write(GpioPinValue.Low);
startTimeDelay =
DateTime
.Now;
while
(
true
)
{
endTimeDelay =
DateTime
.Now;
elapsedMillisecsDelay = ((
TimeSpan
)(endTimeDelay - startTimeDelay)).TotalMilliseconds;
if
(elapsedMillisecsDelay > 1000)
{
for
(
int
k = 0; k < 3; k++)
{
pinSCK.Write(GpioPinValue.Low);
int
count = 0;
while
(pinDT.Read() == GpioPinValue.High) ;
for
(
int
i = 0; i < 8; i++)
{
pinSCK.Write(GpioPinValue.High);
if
(pinDT.Read() == GpioPinValue.High)
{
count++;
}
else
{
}
pinSCK.Write(GpioPinValue.Low);
}
pinSCK.Write(GpioPinValue.Low);
pinSCK.Write(GpioPinValue.High);
//Debug.WriteLine(count.ToString());
data[k] = count;
}
result = data.Average();
if
(result < 5.5)
//result = 5 (Green x 2)
{
pinR.Write(GpioPinValue.Low);
pinG.Write(GpioPinValue.High);
pinB.Write(GpioPinValue.Low);
}
else
if
(result < 6.5 && result >= 5.5)
//result = 6 (Blue x 1)
{
pinR.Write(GpioPinValue.Low);
pinG.Write(GpioPinValue.Low);
pinB.Write(GpioPinValue.High);
}
else
//if (result >= 6.5) //Red x 0
{
pinR.Write(GpioPinValue.High);
pinG.Write(GpioPinValue.Low);
pinB.Write(GpioPinValue.Low);
}
}
}
}
}
}
|
Load cell <-> HX711
Red <-> E+
Black <-> E-
White <-> A+
Blue <-> A-
|
HX711 <-> RPi
GND <-> GND
DT <-> GPIO 23
SCK <-> GPIO 18
VCC <-> 3.3V PWR
|
SCK (SCLK): Serial Clock
MOSI: Master out slave in
MISO: Master in slave out
CS (SS, NSS): Chip select
|
private
const
string
SPI_CONTROLLER_NAME =
"SPI0"
;
private
const
Int32
SPI_CHIP_SELECT_LINE = 0;
private
async
Task
InitSPI()
{
try
{
var
settings =
new
SpiConnectionSettings(SPI_CHIP_SELECT_LINE);
settings.ClockFrequency = 10000000;
settings.Mode = SpiMode.Mode3;
string
spiAqs = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME);
var
devicesInfo =
await
DeviceInformation.FindAllAsync(spiAqs);
spiRFID =
await
SpiDevice.FromIdAsync(devicesInfo[0].Id, settings);
}
catch
(
Exception
ex)
{
throw
new
Exception
(
"SPI Initialization Failed"
, ex);
}
}
|
bit1 = 1 - One for a read OR 0 - Zero for a write
bit2 = A5 - MSB of the address
bit3 = A4 - Next address bit
bit4 = A3 - Next address bit
bit5 = A2 - Next address bit
bit6 = A1 - Next address bit
bit7 = A0 – LSB of the address
bit8 = 0 – Zero
|
MSB: Most significant bit
LSB: Least significant bit
|
private
byte
getFirmwareVersion()
{
byte
version = readMFRC522(VersionReg);
return
version;
}
private
byte
readMFRC522(
byte
register)
{
byte
[] writeBuffer =
new
byte
[2] {
Convert
.ToByte(((register << 1) & 0x7E) | 0x80), 0x00 };
byte
[] readBuffer =
new
byte
[2];
spiRFID.TransferFullDuplex(writeBuffer, readBuffer);
return
readBuffer[1];
}
|
((0x37<<1) & 0x7E ) | 0x80
|
((0x37<<1) & 0x7E ) | 0x80 (hexadecimal representation)
((00110111<<1) & 01111110) | 10000000 (converted all values to binary)
(01101110 & 01111110) | 10000000 (applied bit shift)
01101110 | 10000000 (applied AND operation)
1110111
0 (applied OR operation)
|
(RegisterAddress<<1) & 0x7E
|
private
void
antennaOn()
{
byte
tmp = readMFRC522(TxControlReg);
int
result = (tmp & 0x03);
if
(result == 0)
{
setBitMask(TxControlReg, 0x03);
}
}
private
void
setBitMask(
byte
register,
byte
mask)
{
byte
tmp = readMFRC522(register);
byte
data =
Convert
.ToByte(tmp | mask);
writeMFRC522(register, data);
}
|
TxControlRegData | 0x03
|
For example, TxControlRegData = 00000000
0x00 | 0x03 (hexadecimal representation)
00000000 | 00000011 (converted all values to binary)
000000
11 (applied OR operation)
|
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Net.Http;
using
Windows.ApplicationModel.Background;
using
Windows.Devices.Gpio;
using
Windows.Devices.Spi;
using
Windows.Devices.Enumeration;
using
Windows.System.Threading;
using
System.Diagnostics;
using
System.Threading.Tasks;
namespace
AlexBackgroundApplication
{
public
sealed
class
StartupTask
: IBackgroundTask
{
private
const
int
MAX_LEN = 16;
private
const
byte
PCD_IDLE = 0x00;
private
const
byte
PCD_AUTHENT = 0x0E;
private
const
byte
PCD_RECEIVE = 0x08;
private
const
byte
PCD_TRANSMIT = 0x04;
private
const
byte
PCD_TRANSCEIVE = 0x0C;
private
const
byte
PCD_RESETPHASE = 0x0F;
private
const
byte
PCD_CALCCRC = 0x03;
private
const
byte
PICC_REQIDL = 0x26;
private
const
byte
PICC_REQALL = 0x52;
private
const
byte
PICC_ANTICOLL = 0x93;
private
const
byte
PICC_SELECTTAG = 0x93;
private
const
byte
PICC_AUTHENT1A = 0x60;
private
const
byte
PICC_AUTHENT1B = 0x61;
private
const
byte
PICC_READ = 0x30;
private
const
byte
PICC_WRITE = 0xA0;
private
const
byte
PICC_DECREMENT = 0xC0;
private
const
byte
PICC_INCREMENT = 0xC1;
private
const
byte
PICC_RESTORE = 0xC2;
private
const
byte
PICC_TRANSFER = 0xB0;
private
const
byte
PICC_HALT = 0x50;
private
const
int
MI_OK = 0;
private
const
int
MI_NOTAGERR = 1;
private
const
int
MI_ERR = 2;
private
const
byte
Reserved00 = 0x00;
private
const
byte
CommandReg = 0x01;
private
const
byte
CommIEnReg = 0x02;
private
const
byte
DivlEnReg = 0x03;
private
const
byte
CommIrqReg = 0x04;
private
const
byte
DivIrqReg = 0x05;
private
const
byte
ErrorReg = 0x06;
private
const
byte
Status1Reg = 0x07;
private
const
byte
Status2Reg = 0x08;
private
const
byte
FIFODataReg = 0x09;
private
const
byte
FIFOLevelReg = 0x0A;
private
const
byte
WaterLevelReg = 0x0B;
private
const
byte
ControlReg = 0x0C;
private
const
byte
BitFramingReg = 0x0D;
private
const
byte
CollReg = 0x0E;
private
const
byte
Reserved01 = 0x0F;
private
const
byte
Reserved10 = 0x10;
private
const
byte
ModeReg = 0x11;
private
const
byte
TxModeReg = 0x12;
private
const
byte
RxModeReg = 0x13;
private
const
byte
TxControlReg = 0x14;
private
const
byte
TxAutoReg = 0x15;
private
const
byte
TxSelReg = 0x16;
private
const
byte
RxSelReg = 0x17;
private
const
byte
RxThresholdReg = 0x18;
private
const
byte
DemodReg = 0x19;
private
const
byte
Reserved11 = 0x1A;
private
const
byte
Reserved12 = 0x1B;
private
const
byte
MifareReg = 0x1C;
private
const
byte
Reserved13 = 0x1D;
private
const
byte
Reserved14 = 0x1E;
private
const
byte
SerialSpeedReg = 0x1F;
private
const
byte
Reserved20 = 0x20;
private
const
byte
CRCResultRegM = 0x21;
private
const
byte
CRCResultRegL = 0x22;
private
const
byte
Reserved21 = 0x23;
private
const
byte
ModWidthReg = 0x24;
private
const
byte
Reserved22 = 0x25;
private
const
byte
RFCfgReg = 0x26;
private
const
byte
GsNReg = 0x27;
private
const
byte
CWGsPReg = 0x28;
private
const
byte
ModGsPReg = 0x29;
private
const
byte
TModeReg = 0x2A;
private
const
byte
TPrescalerReg = 0x2B;
private
const
byte
TReloadRegH = 0x2C;
private
const
byte
TReloadRegL = 0x2D;
private
const
byte
TCounterValueRegH = 0x2E;
private
const
byte
TCounterValueRegL = 0x2F;
private
const
byte
Reserved30 = 0x30;
private
const
byte
TestSel1Reg = 0x31;
private
const
byte
TestSel2Reg = 0x32;
private
const
byte
TestPinEnReg = 0x33;
private
const
byte
TestPinValueReg = 0x34;
private
const
byte
TestBusReg = 0x35;
private
const
byte
AutoTestReg = 0x36;
private
const
byte
VersionReg = 0x37;
private
const
byte
AnalogTestReg = 0x38;
private
const
byte
TestDAC1Reg = 0x39;
private
const
byte
TestDAC2Reg = 0x3A;
private
const
byte
TestADCReg = 0x3B;
private
const
byte
Reserved31 = 0x3C;
private
const
byte
Reserved32 = 0x3D;
private
const
byte
Reserved33 = 0x3E;
private
const
byte
Reserved34 = 0x3F;
private
enum
Mode
{
isCard,
readCardSerial
};
private
byte
[] serialNumber =
new
byte
[5];
bool
serialFound =
false
;
BackgroundTaskDeferral deferral;
private
GpioPin pinR, pinG, pinB;
private
GpioPin pinRST;
private
SpiDevice spiRFID;
private
const
string
SPI_CONTROLLER_NAME =
"SPI0"
;
private
const
Int32
SPI_CHIP_SELECT_LINE = 0;
public
void
Run(IBackgroundTaskInstance taskInstance)
{
deferral = taskInstance.GetDeferral();
Task
t = InitSPI();
t.Wait();
InitGPIO();
DateTime
startTimeDelay =
DateTime
.Now, endTimeDelay;
double
elapsedMillisecsDelay;
//init();
while
(
true
)
{
endTimeDelay =
DateTime
.Now;
elapsedMillisecsDelay = ((
TimeSpan
)(endTimeDelay - startTimeDelay)).TotalMilliseconds;
if
(elapsedMillisecsDelay > 1000)
{
serialFound =
false
;
init();
//TODO:
test();
//halt();//TODO:
startTimeDelay =
DateTime
.Now;
}
}
}
private
async
Task
InitSPI()
{
try
{
var
settings =
new
SpiConnectionSettings(SPI_CHIP_SELECT_LINE);
settings.ClockFrequency = 10000000;
settings.Mode = SpiMode.Mode3;
string
spiAqs = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME);
var
devicesInfo =
await
DeviceInformation.FindAllAsync(spiAqs);
spiRFID =
await
SpiDevice.FromIdAsync(devicesInfo[0].Id, settings);
}
catch
(
Exception
ex)
{
throw
new
Exception
(
"SPI Initialization Failed"
, ex);
}
}
private
void
InitGPIO()
{
pinRST = GpioController.GetDefault().OpenPin(18);
pinRST.SetDriveMode(GpioPinDriveMode.Output);
pinRST.Write(GpioPinValue.High);
pinR = GpioController.GetDefault().OpenPin(13);
pinR.SetDriveMode(GpioPinDriveMode.Output);
pinG = GpioController.GetDefault().OpenPin(26);
pinG.SetDriveMode(GpioPinDriveMode.Output);
pinB = GpioController.GetDefault().OpenPin(16);
pinB.SetDriveMode(GpioPinDriveMode.Output);
pinR.Write(GpioPinValue.High);
pinG.Write(GpioPinValue.Low);
pinB.Write(GpioPinValue.Low);
}
private
void
writeMFRC522(
byte
register,
byte
data)
{
byte
[] writeBuffer =
new
byte
[2] {
Convert
.ToByte(((register << 1) & 0x7E)), data };
byte
[] readBuffer =
new
byte
[2];
spiRFID.TransferFullDuplex(writeBuffer, readBuffer);
}
private
byte
readMFRC522(
byte
register)
{
byte
[] writeBuffer =
new
byte
[2] {
Convert
.ToByte(((register << 1) & 0x7E) | 0x80), 0x00 };
byte
[] readBuffer =
new
byte
[2];
spiRFID.TransferFullDuplex(writeBuffer, readBuffer);
return
readBuffer[1];
}
private
void
setBitMask(
byte
register,
byte
mask)
{
byte
tmp = readMFRC522(register);
byte
data =
Convert
.ToByte(tmp | mask);
writeMFRC522(register, data);
}
private
void
clearBitMask(
byte
register,
byte
mask)
{
byte
tmp = readMFRC522(register);
byte
data =
Convert
.ToByte(tmp & (~mask));
writeMFRC522(register, data);
}
private
byte
getFirmwareVersion()
{
byte
version = readMFRC522(VersionReg);
return
version;
}
private
void
reset()
{
writeMFRC522(CommandReg, PCD_RESETPHASE);
}
private
void
init()
{
reset();
writeMFRC522(TModeReg, 0x8D);
//writeMFRC522(TPrescalerReg, 0x3E);//Green->Blue->Green
writeMFRC522(TModeReg, 0x3E);
//Green->Red;Blue->Red
writeMFRC522(TReloadRegL, 0x1E);
writeMFRC522(TReloadRegH, 0x00);
writeMFRC522(TxAutoReg, 0x40);
writeMFRC522(ModeReg, 0x3D);
antennaOn();
}
private
void
antennaOn()
{
byte
tmp = readMFRC522(TxControlReg);
int
result = (tmp & 0x03);
if
(result == 0)
{
setBitMask(TxControlReg, 0x03);
}
}
private
byte
MFRC522ToCard(Mode mode)
{
byte
status = MI_ERR;
byte
tmp = 0x00;
byte
data =
Convert
.ToByte(0x77 | 0x80);
writeMFRC522(CommIEnReg, data);
clearBitMask(CommIrqReg, 0x80);
setBitMask(FIFOLevelReg, 0x80);
writeMFRC522(CommandReg, PCD_IDLE);
if
(mode == Mode.isCard)
{
writeMFRC522(FIFODataReg, PICC_REQIDL);
}
if
(mode == Mode.readCardSerial)
{
writeMFRC522(FIFODataReg, PICC_ANTICOLL);
writeMFRC522(FIFODataReg, 0x20);
}
writeMFRC522(CommandReg, PCD_TRANSCEIVE);
setBitMask(BitFramingReg, 0x80);
int
i = 2000;
int
j = 0, k = 0;
int
n = 0, m = 0;
do
{
tmp = readMFRC522(CommIrqReg);
j = (tmp & 0x01);
k = (tmp & 0x30);
i--;
}
while
((i != 0) && (j == 0) && (k == 0));
clearBitMask(BitFramingReg, 0x80);
if
(i != 0)
{
tmp = readMFRC522(ErrorReg);
j = (tmp & 0x1B);
if
(j == 0)
{
status = MI_OK;
if
(mode == Mode.readCardSerial)
{
tmp = readMFRC522(FIFOLevelReg);
n =
Convert
.ToInt16(tmp);
tmp = readMFRC522(ControlReg);
m = (tmp & 0x07);
if
(n == 0)
{
n = 1;
}
if
(n > MAX_LEN)
{
n = MAX_LEN;
}
for
(i = 0; i < n; i++)
{
data = readMFRC522(FIFODataReg);
serialNumber[i] = data;
}
}
}
else
{
status = MI_ERR;
}
}
return
status;
}
private
byte
MFRC522Request(Mode mode)
{
byte
status = MI_ERR;
writeMFRC522(BitFramingReg, 0x07);
status = MFRC522ToCard(mode);
return
status;
}
private
bool
isCard()
{
byte
status = MI_ERR;
status = MFRC522Request(Mode.isCard);
if
(status == MI_OK)
{
return
true
;
}
else
{
return
false
;
}
}
private
byte
anticoll(Mode mode)
{
byte
status = MI_ERR;
writeMFRC522(BitFramingReg, 0x00);
status = MFRC522ToCard(mode);
return
status;
}
private
bool
readCardSerial()
{
byte
status = MI_ERR;
status = anticoll(Mode.readCardSerial);
if
(status == MI_OK)
{
return
true
;
}
else
{
return
false
;
}
}
private
void
test()
{
if
(isCard() ==
true
)
{
if
(readCardSerial() ==
true
)
{
serialFound =
true
;
if
(serialNumber[0] == 0xB4)
//Round tag = Green
{
pinR.Write(GpioPinValue.Low);
pinG.Write(GpioPinValue.High);
pinB.Write(GpioPinValue.Low);
}
else
if
(serialNumber[0] == 0x7E)
//Rectangular tag = Blue
{
pinR.Write(GpioPinValue.Low);
pinG.Write(GpioPinValue.Low);
pinB.Write(GpioPinValue.High);
}
else
{
serialFound =
false
;
}
}
}
if
(serialFound ==
false
)
//Not found = Red
{
pinR.Write(GpioPinValue.High);
pinG.Write(GpioPinValue.Low);
pinB.Write(GpioPinValue.Low);
}
}
private
void
calculateCRC()
{
//TODO:
}
private
void
halt()
{
//TODO:
}
}
}
|
RFID RC522
VCC <-> 3.3V PWR
RST <-> GPIO 18
GND <-> GND
MISO <-> SPI0 MISO
MOSI <-> SPI0 MOSI
SCK <-> SPI0 SCLK
NSS <-> SPI0 CS0
IRQ (Not connected)
|
static void AlexAssignBOM(Args _args)
{
#define.KanbanId(
"000576")
#define.BOMId(
"000525")
Kanban kanban;
KanbanId kanbanId = #KanbanId;
BOMId bomId = #BOMId;
kanban = Kanban::findKanbanId(kanbanId);
if (kanban && kanban.checkBOMId(bomId))
{
kanban.setKanbanBOMId(bomId,
true,
true);
}
info(
"Done!");
}
|
static void AlexCompleteWithDetails(Args _args)
{
#define.RecId(
5637158182)
Args args =
new Args();
KanbanJobSchedule kanbanJobSchedule;
KanbanJob kanbanJob;
Kanban kanban;
KanbanRule kanbanRule;
KanbanRuleFixed kanbanRuleFixed;
InventTable inventTable;
KanbanBoardTmpProcessJob kanbanBoardTmpProcessJob;
RecId recId;
Map autoMap;
/* Test */
recId = #RecId;
/* Test */
kanban = Kanban::findKanbanJobRecId(recId);
kanbanJob = kanbanJob::find(recId);
kanbanJobSchedule = kanbanJob.kanbanJobSchedule();
kanbanRule = KanbanRule::find(kanban.KanbanRule);
kanbanRuleFixed = KanbanRuleFixed::findParentRecId(kanbanRule.RecId);
inventTable = InventTable::find(kanban.ItemId);
/* Tmp */
kanbanBoardTmpProcessJob.clear();
kanbanBoardTmpProcessJob.Kanban = kanban.RecId;
kanbanBoardTmpProcessJob.KanbanRule = kanban.KanbanRule;
kanbanBoardTmpProcessJob.ItemId = kanban.ItemId;
kanbanBoardTmpProcessJob.InventDimId = kanban.InventDimId;
kanbanBoardTmpProcessJob.Express = kanban.Express;
kanbanBoardTmpProcessJob.CardId = kanban.KanbanCardId;
kanbanBoardTmpProcessJob.QuantityOrdered = kanbanJob.QuantityOrdered;
kanbanBoardTmpProcessJob.Status = kanbanJob.Status;
kanbanBoardTmpProcessJob.Job = kanbanJob.RecId;
kanbanBoardTmpProcessJob.ExpectedDateTime = kanbanJob.ExpectedDateTime;
kanbanBoardTmpProcessJob.DueDateTime = kanbanJob.DueDateTime;
kanbanBoardTmpProcessJob.ActualEndDateTime = kanbanJob.ActualEndDateTime;
kanbanBoardTmpProcessJob.PlannedPeriod = kanbanJobSchedule.PlannedPeriod;
kanbanBoardTmpProcessJob.Sequence = kanbanJobSchedule.Sequence;
kanbanBoardTmpProcessJob.ActivityName = kanbanJob.PlanActivityName;
kanbanBoardTmpProcessJob.ReceiptInventLocationId = kanbanJob.InventLocationId;
kanbanBoardTmpProcessJob.ReceiptWMSLocationId = kanbanJob.wmsLocationId;
kanbanBoardTmpProcessJob.ItemName = inventTable.defaultProductName();
kanbanBoardTmpProcessJob.Color = kanbanJob.LeanScheduleGroupColor;
kanbanBoardTmpProcessJob.ScheduleGroupName = kanbanJob.LeanScheduleGroupName;
kanbanBoardTmpProcessJob.IsOverdue = KanbanJob::isOverdue(
kanbanJob.DueDateTime,
kanbanJob.ExpectedDateTime,
kanbanJob.Status,
kanbanRule.ReplenishmentStrategy,
kanbanRuleFixed.ReplenishmentLeadTime);
kanbanBoardTmpProcessJob.insert();
/* Tmp */
args.record(kanbanBoardTmpProcessJob);
//args.caller(kanbanMultiJob);
args.parmEnumType(enumnum(KanbanMultiMode));
args.parmEnum(KanbanMultiMode::Auto);
autoMap = new Map(Types::Int64, Types::Container);
autoMap.insert(kanbanBoardTmpProcessJob.Job, [kanbanBoardTmpProcessJob.QuantityOrdered, 0]);
KanbanMultiJob::newArgs(args, LeanKanbanJobStatus::Completed).runAuto(autoMap);
info(
"Done!");
}
|
public static KanbanMultiMode kanbanMultiMode(Args _args)
{
KanbanMultiMode kanbanMultiMode;
if ( _args
&& (_args.parmEnumType() ==
enumnum(RunChoose)
|| (_args.parmEnumType() ==
enumnum(KanbanMultiMode)
&& _args.parmEnum() == KanbanMultiMode::Form)))
{
kanbanMultiMode = KanbanMultiMode::Form;
}
else
{
//alex:>>
if (_args.parmEnumType() == enumnum(KanbanMultiMode) &&
_args.parmEnum() == KanbanMultiMode::Auto)
{
kanbanMultiMode = KanbanMultiMode::Auto;
}
else
{
kanbanMultiMode = KanbanMultiMode::Silent;
}
//alex:<<
}
return kanbanMultiMode;
}
|
protected void initAuto(Map _autoMap =
null)
{
}
|
public void runAuto(Map _autoMap =
null)
{
KanbanJobStatusUpdate kanbanJobStatusUpdate;
if
(kanbanMultiMode == kanbanMultiMode::Auto && _autoMap != null)//alex:
{
this.initStatusUpdate();
this.initAuto(_autoMap);//alex:
if (! this.validate())
{
throw error(
"@SYS18447");
}
this.preRun();
kanbanJobStatusUpdate = this.setParmBuffer();
while (kanbanJobStatusUpdate)
{
try
{
if (this.isStatusReset())
{
this.runStatusReset(kanbanJobStatusUpdate);
}
else
{
KanbanMultiJob::callIL([
classIdGet(this), buf2Con(kanbanJobStatusUpdate,
true), this.pack()]);
}
next kanbanJobStatusUpdate;
}
catch (Exception::Error)
{
next kanbanJobStatusUpdate;
}
}
this.postRun();
}
else
{
error(
"Automatic update has been canceled.");
}
}
|
protected void initAuto(Map _autoMap =
null)
{
KanbanJobStatusUpdate kanbanJobStatusUpdate;
KanbanJobQuantityReceived qtyReceived;
KanbanJobQuantityScrapped qtyScrapped;
MapIterator autoMapIterator;
RefRecId recId;
container con;
ttsbegin;
if (_autoMap !=
null)
{
autoMapIterator =
new MapIterator(_autoMap);
while (autoMapIterator.more())
{
recId = autoMapIterator.key();
con = autoMapIterator.value();
qtyReceived = conPeek(con, 1);//kanbanBoardTmpProcessJob.QuantityOrdered
qtyScrapped = conPeek(con, 2);//0
while select forupdate kanbanJobStatusUpdate
where kanbanJobStatusUpdate.ParmId == this.parmId() &&
kanbanJobStatusUpdate.Job == recId
{
//kanbanJobStatusUpdate.KanbanId
//kanbanJobStatusUpdate.Job
kanbanJobStatusUpdate.QuantityReceived = qtyReceived;
kanbanJobStatusUpdate.QuantityScrapped = qtyScrapped;
kanbanJobStatusUpdate.update();
}
autoMapIterator.next();
}
}
ttscommit;
}
|