@tsplc/compiler 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "url": "git+https://github.com/rip-technologies/tsplc.git",
18
18
  "directory": "packages/compiler"
19
19
  },
20
- "version": "0.4.2",
20
+ "version": "0.4.4",
21
21
  "type": "module",
22
22
  "exports": {
23
23
  ".": {
@@ -101,17 +101,17 @@
101
101
  "bun": ">=1.4.3"
102
102
  },
103
103
  "dependencies": {
104
- "@tsplc/agent": "0.4.2",
105
- "@tsplc/build": "0.4.2",
106
- "@tsplc/config": "0.4.2",
107
- "@tsplc/debug": "0.4.2",
108
- "@tsplc/opcua": "0.4.2",
109
- "@tsplc/typegen": "0.4.2",
104
+ "@tsplc/agent": "0.4.4",
105
+ "@tsplc/build": "0.4.4",
106
+ "@tsplc/config": "0.4.4",
107
+ "@tsplc/debug": "0.4.4",
108
+ "@tsplc/opcua": "0.4.4",
109
+ "@tsplc/typegen": "0.4.4",
110
110
  "typescript": "6.0.3",
111
111
  "zod": "4.3.6",
112
112
  "@types/bun": "1.4.2",
113
- "@tsplc/server": "0.4.2",
114
- "@tsplc/iec": "0.4.2"
113
+ "@tsplc/server": "0.4.4",
114
+ "@tsplc/iec": "0.4.4"
115
115
  },
116
116
  "bin": {
117
117
  "tsplc": "./dist/cli.js"
@@ -417,7 +417,7 @@ const httpServiceBlock = (
417
417
  network: string,
418
418
  /** The requesting job's id input and this block's request counter, sent as `x-tsplc-request`. */
419
419
  trace: { job: string; sequence: string } | undefined,
420
- ): GeneratedObject =>
420
+ ): [GeneratedObject, GeneratedObject] =>
421
421
  nativeHttp({
422
422
  id: block.id,
423
423
  name,
@@ -470,12 +470,14 @@ export const nativeHttp = ({
470
470
  decode: string;
471
471
  /** The requesting job's id input and this block's request counter, sent as `x-tsplc-request`. */
472
472
  trace?: { job: string; sequence: string };
473
- }): GeneratedObject => {
473
+ }): [GeneratedObject, GeneratedObject] => {
474
474
  const requestHeader = trace
475
475
  ? `AppendWire(UDINT_TO_STRING(${trace.job}));AppendWire(':');AppendWire(UDINT_TO_STRING(${trace.sequence}));AppendWire('$R$NContent-Length: ');`
476
476
  : "";
477
+ const release =
478
+ "resolver(xExecute:=FALSE,itfIPAddress:=remoteIP);client(xEnable:=FALSE);writer(xExecute:=FALSE);reader(xEnable:=FALSE);timeout(IN:=FALSE);";
477
479
  // Helpers are emitted as native methods under the HTTP block by the emitter.
478
- return {
480
+ const block: GeneratedObject = {
479
481
  id,
480
482
  kind: "functionBlock",
481
483
  name,
@@ -513,7 +515,7 @@ END_VAR
513
515
  // The host goes in the resolver call, not an initial value: an online change keeps the values
514
516
  // an instance already holds, so a changed host would otherwise wait for a download.
515
517
  implementation: `IF NOT ${port("start")} OR ${port("cancel")} THEN
516
- resolver(xExecute:=FALSE,itfIPAddress:=remoteIP);client(xEnable:=FALSE); writer(xExecute:=FALSE); reader(xEnable:=FALSE); timeout(IN:=FALSE);
518
+ ${release}
517
519
  stage:=0; ${port("busy")}:=FALSE; ${port("done")}:=FALSE; ${port("error")}:=0;
518
520
  RETURN;
519
521
  END_IF;
@@ -573,11 +575,28 @@ IF stage=3 THEN
573
575
  END_IF;
574
576
  END_IF;
575
577
  IF stage=90 THEN
576
- resolver(xExecute:=FALSE,itfIPAddress:=remoteIP);client(xEnable:=FALSE);writer(xExecute:=FALSE);reader(xEnable:=FALSE);timeout(IN:=FALSE);
578
+ ${release}
577
579
  ${port("busy")}:=FALSE;${port("done")}:=TRUE;
578
580
  END_IF;
579
581
  `,
580
582
  };
583
+ // CODESYS calls FB_exit before a download, reset or application stop discards the instance, and
584
+ // with bInCopyCode before an online change copies it. A connection still open then keeps the
585
+ // Net Base Services task in a socket call, and the runtime can't delete the old application's
586
+ // tasks until it restarts. A request this interrupts completes as a network error rather than
587
+ // being sent again, since tsPLC never repeats a remote side effect.
588
+ const exit: GeneratedObject = {
589
+ id: `${id}:FB_exit`,
590
+ parent: id,
591
+ kind: "method",
592
+ name: "FB_exit",
593
+ declaration:
594
+ "METHOD PUBLIC FB_exit : BOOL\nVAR_INPUT\n bInCopyCode : BOOL;\nEND_VAR",
595
+ implementation: `IF stage>0 AND stage<90 THEN ${port("error")}:=${jobError.network};stage:=90;END_IF;
596
+ ${release}
597
+ FB_exit:=TRUE;`,
598
+ };
599
+ return [block, exit];
581
600
  };
582
601
 
583
602
  export const httpCertificateVerifier = (
@@ -848,8 +867,8 @@ END_VAR`,
848
867
  symbols.targetTypes,
849
868
  );
850
869
  const requestFields = instrumentation.fields.get(fn.id);
851
- const generated = rpcGlobal
852
- ? opcuaServiceBlock(fn, name, codecs, endpoint, rpcGlobal)
870
+ const [generated, ...lifecycle] = rpcGlobal
871
+ ? [opcuaServiceBlock(fn, name, codecs, endpoint, rpcGlobal)]
853
872
  : httpServiceBlock(
854
873
  fn,
855
874
  name,
@@ -862,6 +881,7 @@ END_VAR`,
862
881
  );
863
882
  objects.push(
864
883
  generated,
884
+ ...lifecycle,
865
885
  ...httpMethods(generated.id, endpoint.transport),
866
886
  ...httpCertificateVerifier(generated.id, generated.name, endpoint),
867
887
  );
@@ -623,7 +623,7 @@ export function telemetryObjects({
623
623
  const helpers = httpMethods(writer).filter((item) =>
624
624
  ["ByteLength", "Append", "WriteString"].includes(item.name),
625
625
  );
626
- const client = nativeHttp({
626
+ const [client, clientExit] = nativeHttp({
627
627
  id: telemetryClient,
628
628
  name: names.client,
629
629
  ports: `VAR_INPUT\nstart : BOOL;\ncancel : BOOL;\nEND_VAR\nVAR_IN_OUT\nbody : STRING(${plcBufferBytes});\nEND_VAR\nVAR_OUTPUT\nbusy : BOOL;\ndone : BOOL;\nerror : UDINT;\nEND_VAR`,
@@ -773,6 +773,7 @@ WriteString(text);
773
773
  ...failures,
774
774
  ...trace,
775
775
  client,
776
+ clientExit,
776
777
  ...httpMethods(telemetryClient),
777
778
  ...httpCertificateVerifier(telemetryClient, names.client, endpoint),
778
779
  ];